Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ajax - Post data to RESTful Invalid HTTP status code 405

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

 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 Allowed in firefox and Invalid HTTP status code 405 , XMLHttpRequest cannot load url in chrome.

Note: When I use Rest Client of Chrome to POST to web service, it worked.

Any help would be much appreciated, thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/

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.

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

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...