请求非ajax,非ajax jQuery POST请求

本文讲述了如何使用非AJAX的jQuery进行POST请求,通过模拟表单提交实现页面跳转,并提供了具体代码示例。 Doug Neiner建议避免常规POST,除非必要,且展示了如何在PHP中获取POST数据的方法。
摘要由CSDN通过智能技术生成

amit提出了一个问题:non-AJAX jquery POST request,或许与您遇到的问题类似。

回答者Doug Neiner给出了该问题的处理方式:

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 ...

If you have to use POST, then do this to get the page to follow your call:

$("#see_comments").click(function() {

$('

' +

'' +

'

').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'])

希望本文对你有帮助,欢迎支持JavaScript中文网

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值