![](/img/trans.png)
[英]jQuery: Get request (GET/POST) parameters from ajax request in Javascript
[英]why not get POST parameters in ajax POST of jQuery
下面列出了代码:
$.ajax({
type: "POST",
url: "http://localhost:3000/rcm/global_config/update",
data: {k: 'sdfa', v: 'dsfas'},
success: function(data, textStatus, XMLHttpRequest){
alert("数据更新成功");
},
error: function(xhr,textStatus, errorThrown){
alert("数据更新失败,请刷新回滚");
}
});
在服务器中,我无法获取post参数,然后篡改ajax发送的请求,它根本不发送数据参数。 我不知道我在哪里错。
先感谢您。
这样的问题已在SO Jquery -ajax-post- send -options-as-request-method-in-firefox中被询问和提出
这是因为在FF上具有相同的来源策略。 它仅允许您对自己的域执行XMLHTTPRequests。 也许您的脚本是从域“ localhost”加载的,而您的ajax请求已加载到“ localhost:3000”
请尝试这个
$.ajax({
type: "POST",
url: "http://localhost:3000/rcm/global_config/update",
data: "{'k': 'sdfa', 'v': 'dsfas'}", // Change are here in this line
success: function(data, textStatus, XMLHttpRequest){
alert("数据更新成功");
},
error: function(xhr,textStatus, errorThrown){
alert("数据更新失败,请刷新回滚");
}
});
$.ajax({
type: "POST",
url: "http://localhost:3000/rcm/global_config/update",
data: $.param({k: 'sdfa', v: 'dsfas'}),
success: function(data, textStatus, XMLHttpRequest){
alert("数据更新成功");
},
error: function(xhr,textStatus, errorThrown){
alert("数据更新失败,请刷新回滚");
}
});
将数据对象包装在$ .param中即可。 它将将该对象转换为字符串“ k = sdfa&v = dsfas”
嗨,请尝试这样的事情:
$.ajax({
type:"POST",
url:"student/info/ajax.php",
data:({type:'test', r:which}),
success:function(data){
if((data.result)=='true')
$('#result_popup').html(data.output);
},
dataType:"json"});
return false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.