我正在尝试使用jquery POST函数,但它正在以AJAX样式处理请求。我的意思是它实际上没有进入我要告诉它的页面。
i am trying to use the jquery POST function but it is handling the request in AJAX style. i mean its not actually going to the page I am telling it to go.
$("#see_comments").click(function() { $.post( "comments.php", {aid: imgnum}, function(data){ }); });这个函数应该带有辅助值到comments.php页面。它的发布很好但没有重定向到comments.php。
this function should go to comments.php page with the aid value in hand. its posting fine but not redirecting to comments.php.
@Doug Neiner 澄清: 1我有15个链接(图片)。我点击一个链接,它加载我的JavaScript。 JS知道我打开了wat imgnum。我想在comments.php中找到这个imgnum。我必须使用这个JavaScript,没有其他方法可以做到这一点。 JS是强制性的。 2.您的方法成功发布援助值。但在comments.php中,当我尝试回显该值时,它什么也没显示。 3.我正在使用Firebug。在控制台中,它显示了我在步骤(2)中成功完成的回显REQUEST。
@Doug Neiner clarification: 1. I have 15 links (images). i click on a link and it loads my javascript. the JS knows wat imgnum i opened. this imgnum i want in the comments.php. i have to use this javascript and no other means can do the trick. the JS is mandatory. 2. your method successfully POSTs the aid value. but in the comments.php when i try to echo that value, it displays nothing. 3. 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.
首先,除非您在服务器上更改数据,否则请勿使用 POST 请求。只需 #see_comments 是正常的< a href ='/ comments.php?aid = 1'> ...
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'>...
如果 使用 POST ,那么这样做就可以了跟随您的通话的页面:
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(); });这实际上是如何运作的。
第一个 $。post 仅一个AJAX方法,不能用来做传统的表单提交就像你描述的那样。因此,为了能够发布值和导航到新页面,我们需要模拟表单帖子。
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.
所以流程如下:
更多推荐
非AJAX jquery POST请求
发布评论