I create a method to send json data to a 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:"test.abc@gmail.com", Phone:"011123456", WebAccount:"test.abc@gmail.com", 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 the 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 from Chrome to POST for the web service, it worked.
Any help would be greatly appreciated, thanks.
rest ajax
Nothing
source share