admin管理员组文章数量:1355093
So I have an ajax script that runs, it looks like this:
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'
So I have an ajax script that runs, it looks like this:
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'
Share Improve this question edited Apr 8, 2015 at 11:27 CommunityBot 11 silver badge asked Apr 8, 2015 at 9:11 MatthewMatthew 591 gold badge2 silver badges9 bronze badges 3- 2 What is your backend ? it may be possible that the server side is not allowing post action ? – Igoris Commented Apr 8, 2015 at 9:20
- Wordpress backend. But it works fine with my other script which runs almost the exact same code. @IgorisAzanovas – Matthew Commented Apr 8, 2015 at 9:24
- Try getting post data through general <form> tag with submit button to check if all data that i'm passign is ok and it load without ajax. – Igoris Commented Apr 8, 2015 at 10:04
3 Answers
Reset to default 3Here 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);
},
});
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.
It turns out I forgot to add the name="" parameter in my input types. Doh!
本文标签: javascriptjQuery Ajax returning 404 when methodpostStack Overflow
版权声明:本文标题:javascript - jQuery Ajax returning 404 when method = post - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744008636a2575155.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论