如何通过jQuery AJAX请求同时发送GET和POST参数?
我正在尝试将do=ajax&id=" + ID
添加到url
,但结果请求仅发送到没有查询字符串(get part)的sss.php
。谢谢。
$.ajax({
url: "sss.php?do=ajax&id=" + ID ,
type: "post",
data: "ddd=sss",
// callback handler that will be called on success
success: function(response, textStatus, jqXHR){
// log a message to the console
console.log("Hooray, it worked!");
},
// callback handler that will be called on error
error: function(jqXHR, textStatus, errorThrown){
// log the error to the console
console.log(
"The following error occured: "+
textStatus, errorThrown
);
}
});
发布于 2012-10-01 20:34:25
我认为您得到的是观察性错误,或者看到的是服务器端而不是jQuery问题。当我做一个post like this时
$.ajax({
url: "http://jsbin.com/eduzif/1?foo=bar",
type: "post",
data: "baz=doh",
success: function() {
display("Done, look at your console's network tab");
}
});
...both将查询字符串和POST数据发送到服务器。如果你使用像Chrome或Firefox这样的现代浏览器,并在触发post后查看控制台的网络选项卡,那么很容易检查这一点。在我的例子中:
(您可以忽略上面的服务器回复了403;JSBin不允许POST,但这不会影响我们在发送到服务器的请求中看到的内容。)
因此,这里的答案是:仔细检查您是如何在服务器端获得数据的。URL中的参数("GET“样式参数)可用作查询字符串参数(URL的一部分);"POST”样式参数可用作“表单”数据(例如,响应的主体)。根据您使用的服务器端技术,通常有不同的方法来检索GET (查询字符串)参数和POST (表单数据/正文)参数。
https://stackoverflow.com/questions/12680522
复制相似问题