tags:

views:

83

answers:

1

ive got a forum. when i click on a thread it passes GET variables through URL to another php page that displays that thread.

 url?threadid=10

and ive got a reply form in the bottom. when the user click submit reply it will execute jquery that call a php through ajax. i have to pass the threadid variable to the ajaxcalled php file but i dont know how to do that.

ive tried in phpfile:

  $threadid = $_GET['threadid'];
  include "jsfile.php";

and then in jsfile:

  <script ...> 
  $.get("static/js/ajaxcall_reply.php", {threadid: '<?php echo $threadid ?>'}, function(data) {
  </script>

but that doesnt work. how can i do it? what is the right way to go here. cookies? json? please help!

EDIT: btw...isnt this approach bad. because to be able to have php code in js file i have to include it as a php file and cant use to link to it in php file? im a little bit lost...

+2  A: 

threadid is a request variable, so I think you'd need to get that from the $_GET array:

$.get("static/js/ajaxcall_reply.php", {threadid: '<?php echo $_GET["threadid"] ?>'}, function(data) {

This page describes the $_GET array in more detail. It contains request variables from the URL. The array I had previously suggested ($_REQUEST) would also work.

Kaleb Brasee
Wouldn't it be better to use $_GET['threadid']?
middus
Yeah, $_GET would work too, and would actually ensure that it's using the URL variable. Might avoid some potential problems with variables in other contexts. I'll change it to that.
Kaleb Brasee
Maybe he's calling extract() on $_REQUEST, which i would never do.
Jacob Relkin