jquery ajax post querystring
刚刚开始熟悉jquery和ajax 我想在一个页面上运行一个小脚本,我已经收集到我需要使用jquery函数中的POST来实现这一点。但我在发送查询时遇到了问题,我做错了什么jquery ajax post querystring,jquery,ajax,query-string,Jquery,Ajax,Query String,刚刚开始熟悉jquery和ajax 我想在一个页面上运行一个小脚本,我已经收集到我需要使用jquery函数中的POST来实现这一点。但我在发送查询时遇到了问题,我做错了什么 $.post("inventory.php?use=" + drag_item.attr('id')); 拖动项。attr('id')是一个很小的单字文本,这样做对吗?您应该对参数进行编码: $.post("inventory.php", { use: drag_item.attr('id') }); 同样在本例中,为了
$.post("inventory.php?use=" + drag_item.attr('id'));
拖动项。attr('id')是一个很小的单字文本,这样做对吗?您应该对参数进行编码:
$.post("inventory.php", { use: drag_item.attr('id') });
同样在本例中,为了处理服务器返回的结果,您只发送一个AJAX请求,但从不订阅任何成功回调。你可以这样做:
$.post("inventory.php", { use: drag_item.attr('id') }, function(result) {
// this will be executed when the AJAX call succeeds and the result
// variable will contain the response from the inventory.php script execution
});
还要确保您在本例中使用的drag\u项
已正确初始化为某个现有DOM元素,并且该DOM元素具有id
属性
最后,使用javascript调试工具,如FireFox中的FireBug或Google Chrome中的Chrome developer toolbar,调试AJAX请求,查看发送到服务器和从服务器发送的请求和响应,以及其间可能发生的任何错误
$.post("inventory.php?use=" + drag_item.attr('id')); //wrong
这是错误的,为此需要一组额外的参数:
$.post("inventory.php",{use:''+drag_item.attr('id')},function(responseData){
//callback goes here
});
谢谢,所以我可以在inventory.php上使用普通的$_GET[use]方法来处理数据是吗?你说的那些DOM话把我弄糊涂了,但我想我会解决的。@user1022585,不,你不能在服务器端脚本中使用
$\u GET[“use”]
,因为你没有发送GET请求。您正在从客户端发送POST请求,因此应该在服务器上使用$\u POST[“use”]
来获取相应的值。或者修改客户端脚本以使用$。get
而不是$。post
。