简体   繁体   English

当方法=发布时,jQuery Ajax返回404

[英]jQuery Ajax returning 404 when method = post

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' 这可以正常运行,但是如果我删除了“ type:post”,则从设置为“ url”的页面返回404

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);
                },
            }); 

如果省略type: 'POST' ,则jQuery将其GET请求,默认情况下将看到docs该文档中的资源可能不存在,因此会导致您看到404

It turns out I forgot to add the name="" parameter in my input types. 原来我忘了在输入类型中添加name =“”参数。 Doh! 卫生署!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM