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 POST
request. Just have #see_comments
be 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:
$("#see_comments").click(function() {
$('<form action="comments.php" method="POST">' +
'<input type="hidden" name="aid" value="' + imgnum + '">' +
'</form>').submit();
});
How this would actually work.
First $.post
is only an AJAX method and cannot be used to do a traditional form
submit like you are describing. So, to be able to post a value and navigate to the new page, we need to simulate a form
post.
So the flow is as follows:
- You click on the image, and your JS code gets the
imgnum
- Next, someone clicks on
#see_comments
- We create a temporary
form
with the imgnum
value in it as a hidden field
- We submit that form, which posts the value and loads the
comments.php
page
- Your
comments.php
page will have access to the posted variable (i.e. in PHP it would be $_POST['aid']
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…