send variables from php to jquery?
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?t开发者_开发百科hreadid=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...
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.
精彩评论