我想在页面上运行一个小脚本,并且已经收集到了需要使用的jquery函数中的POST来执行此操作。但我在发送查询字符串时遇到了麻烦——哪里出错了?
$.post("inventory.php?use=" + drag_item.attr('id'));
drag_item.attr('id')是正确的做法吗?
我想在页面上运行一个小脚本,并且已经收集到了需要使用的jquery函数中的POST来执行此操作。但我在发送查询字符串时遇到了麻烦——哪里出错了?
$.post("inventory.php?use=" + drag_item.attr('id'));
drag_item.attr('id')是正确的做法吗?
You should encode the parameters:
$.post("inventory.php", { use: drag_item.attr('id') });
Also in this example you are only sending an AJAX request but never subscribing to any success callback in order to process the results returned by the server. You could do this like that:
$.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
});
Also make sure that the drag_item
that you are using in this example has been properly initialized to some existing DOM element and that this DOM element has an id
attribute.
Finally use a javascript debugging tool such as FireBug in FireFox or Chrome developer toolbar in Google Chrome to debug your AJAX requests and see the requests and responses being sent to and from the server and any possible errors that might occur in between.