javascript 当方法 = 发布时,jQuery Ajax 返回 404
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29510454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Ajax returning 404 when method = post
提问by Matthew
So I have an ajax script that runs, it looks like this:
所以我有一个运行的ajax脚本,它看起来像这样:
jQuery.ajax({
url: 'http://localhost/?page_id=104256',
type: 'POST',
data: { name : 'name2' },
success: function (data) {
alert(data);
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details0: " + desc + "\nError:" + err);
},
});
This runs fine but returns a 404 from the page set as the 'url' If I remove 'type: post'
这运行良好,但从设置为“url”的页面返回 404 如果我删除“类型:发布”
回答by Pratik
Here your method: 'Post', Type is something what you want to get in return like text
这里你的方法是:“发布”,类型是你想要得到的回报,比如文本
jQuery.ajax({
url: 'http://localhost/?page_id=104256',
method: 'POST',
data: { name : 'name2' },
success: function (data) {
alert(data);
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details0: " + desc + "\nError:" + err);
},
});
回答by Matthew
It turns out I forgot to add the name="" parameter in my input types. Doh!
结果我忘记在我的输入类型中添加 name="" 参数。呸!
回答by stephen
If type: 'POST'
is omitted, jQuery is treating it like a GET
request, which it defaults to see the docs, where the resource may not exist therefore resulting in a the 404
you're seeing.
如果type: 'POST'
省略,jQuery 将其视为GET
请求,它默认查看 docs,其中资源可能不存在,因此导致404
您看到的 。