8

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.

2
  • Anyone know about this issue please :(
    – Nothing
    Commented Sep 17, 2013 at 1:59
  • 1
    Give it a try with contentType: "application/json; charset=utf-8",
    – My-Name-Is
    Commented Oct 8, 2013 at 21:55

1 Answer 1

11
+50

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/

3
  • This issue was solved by enable POST in web service.
    – Nothing
    Commented Oct 6, 2013 at 9:25
  • I see the OP has POST, and the answer was to enable POST in ws. But, what if the service uses GET and the call in ajax uses GET? I have this same error.
    – Taersious
    Commented Sep 24, 2015 at 18:22
  • @Taersious, make sure your method has the [HttpGet] attribute, and make sure you are returning your json with something like this return Json(data, JsonRequestBehavior.AllowGet)
    – Tony
    Commented Feb 9, 2016 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.