I am trying to use the jQuery POST function but it is handling the request in AJAX style. I mean it’s not actually going to the page I am telling it to go.
$("#see_comments").click(function() {
$.post(
"comments.php",
{aid: imgnum},
function (data) {
}
);
});
This function should go to comments.php page with the aid value in hand. It’s posting fine but not redirecting to comments.php.
@Doug Neiner Clarification:
-
I have 15 links (images). I click on a link and it loads my JavaScript. The script knows what
imgnumI opened. ThisimgnumI want in the comments.php. I have to use this JavaScript and no other means can do the trick. The JavaScript is mandatory -
Your method successfully POSTs the aid value. But in the comments.php when I try to echo that value, it displays nothing.
-
I am using Firebug. In the Console, it shows the echo REQUEST I made in Step (2) successfully.
I know what you are trying to do, but its not what you want.
First, unless you are changing data on the server, don’t use a
POSTrequest. Just have#see_commentsbe a normal<a href='/comments.php?aid=1'>...If you have to use
POST, then do this to get the page to follow your call:How this would actually work.
First
$.postis only an AJAX method and cannot be used to do a traditionalformsubmit like you are describing. So, to be able to post a value and navigate to the new page, we need to simulate aformpost.So the flow is as follows:
imgnum#see_commentsformwith theimgnumvalue in it as a hidden fieldcomments.phppagecomments.phppage will have access to the posted variable (i.e. in PHP it would be$_POST['aid'])