ajax 将数据发布到 RESTful 无效的 HTTP 状态代码 405

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18825458/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 11:06:06  来源:igfitidea点击:

Post data to RESTful Invalid HTTP status code 405

ajaxrest

提问by Nothing

I create a method to post json data to web service :

我创建了一种将 json 数据发布到 Web 服务的方法:

 function WishList() { }
 WishList.prototype.addToWishList = function(redirectURL, postURL, userObj) {
    $.ajax({
           type: "POST",
           url: postURL,
           data: JSON.stringify(userObj),
           dataType: 'json',
           contentType: "application/json",
           success: function(data){alert(data);},
           failure: function(errMsg) {
              alert(errMsg);
           }
 }

 This is my object:

 var user1 = {
            ID:1,
            Sex:1,
            Name:"titi",
            Company:"ABC",
            Address:"Phnom Penh",
            Email:"[email protected]",
            Phone:"011123456",
            WebAccount:"[email protected]",
            Password:"123456",
            GroupCustomerID:125,
            Stars:1,
            IsVIP:0,
            PriceLevel:1,
            LastDateSale:"\/Date(-62135596800000)\/",
            TotalCredit:150.12,
            AgingData:null,
            TotalRedeemPoint:1000.00,
            RedeemData:null,
            ExchangeRate:155.00,
            HistoryData:null
        };          

 Calling function :

 $(document).ready(function () { 
    var myWishList = new WishList();
    $('#addToWishList').click(function(){
       myWishList.addToWishList('http://www.blahblahblah.com' , 'http://blahblah/Website/Products/Product.svc/Wishlist/' , user1);
    });
 });

Then I got errors in my console : "NetworkError: 405 Method Not Allowedin firefoxand Invalid HTTP status code 405 , XMLHttpRequest cannot load urlin chrome.

然后我的控制台出现错误: "NetworkError: 405 Method Not AllowedinfirefoxInvalid HTTP status code 405 , XMLHttpRequest cannot load urlin chrome

Note: When I use Rest Clientof Chrome to POSTto web service, it worked.

注意:当我使用Rest ClientChromePOST访问网络服务时,它工作正常。

Any help would be much appreciated, thank you.

任何帮助将不胜感激,谢谢。

回答by Tony

Not sure what you are using as the service on the other end but this may be due to cross domain posting. I hate to post a link and run but this may be of some use to you.

不确定您在另一端使用什么作为服务,但这可能是由于跨域发布。我讨厌发布链接并运行,但这可能对您有用。

http://praneeth4victory.wordpress.com/2011/09/29/405-method-not-allowed/

http://praneeth4victory.wordpress.com/2011/09/29/405-method-not-allowed/

Looks like they could get it working in IE but had some issues as you with the other browsers. Perhaps these couple changes will help access the service better.

看起来他们可以让它在 IE 中工作,但在使用其他浏览器时遇到了一些问题。也许这对夫妇的变化将有助于更好地访问服务。

This post was good at explaining the error and parts to it as well so if the above link is not helpful this one may help you diagnose the issue further.

这篇文章很好地解释了错误及其部分,所以如果上面的链接没有帮助,这个链接可以帮助您进一步诊断问题。

http://www.checkupdown.com/status/E405.html

http://www.checkupdown.com/status/E405.html

ok ok last edit, just wanted to make sure you have enough info to hopefully resolve your issue, here is a good article on the underlying problem I believe you are having..

好的,最后一次编辑,只是想确保您有足够的信息来解决您的问题,这是一篇关于潜在问题的好文章,我相信您遇到了..

http://www.d-mueller.de/blog/cross-domain-ajax-guide/

http://www.d-mueller.de/blog/cross-domain-ajax-guide/