I am trying to pass a session variable into an AJAX loaded page. Here is the code I am using:
jQuery(document).ready(function(){
$("#userdetail").click(function() {
$.ajax({
url: "userdetail.php?id=<?php $_SESSION['uid']?>",
success: function(msg){
$("#results").html(msg);
}
});
});
});
This is the HTML URL I had working, not sure how to get this into the AJAX call:
userdetail.php?id=<?php $_SESSION['uid']?>
I should also mention that if I manually pass in the userID it works fine
ur开发者_JS百科l: "userdetail.php?id=1",
If this is what's actually rendering on the page:
userdetail.php?id=<?php $_SESSION['uid']?>
Then it sounds like your PHP interpreter isn't working on the server. That should output the actual value (it may need an echo
or something though, I'm not sure), not the PHP code (which itself should never be output to the client).
Could you try
url: "userdetail.php?id=<?php echo $_SESSION['uid']?>",
Is your file a .js file? PHP interpreter doesn't read .js files by default.
I solved this by echoing the SESSION variable on the page itself rather than using GET. Thanks everyone!
精彩评论