Tag Archives: Ajax error reporting cross domain

Ajax error reporting cross domain, AJAX cross domain access error 501 solution

Problem: Ajax cross domain access error 501

Running the following code will report error 501

$.ajax({

type: “POST”,

url: ” http://192.168.1.202/sensordata.php “,

contentType:’application/json; charset=utf-8′,

data: JSON.stringify(ajaxPostData),

dataType:’json’,

success: function(data){

//On ajax success do this

console.info(“success.”);

if (data[“status”] == “ok”){

alert(“Settings is Ok. The Machine is rebooting.”);

}

},

error: function(xhr, ajaxOptions, thrownError) {

//On error do this

console.info(“error.”);

if (xhr.status == 200) {

alert(ajaxOptions);

}

else {

alert(xhr.status);

alert(thrownError);

}

}

});

resolvent:

Remove contenttype: ‘application/JSON; charset=utf-8’

reason:

1. When cross domain, the browser will be triggered to send a request with the method options first, except that the contenttype is application/x-www-form-urlencoded, multipart/form data or text/plain.

2 for example, your original request is the post method. If the allow attribute in the header of the result returned by the first request does not have the post method,

3 then the second request will not be sent. At this time, the browser console will report an error and tell you that the post method is not supported by the server.

The above is the whole content of this article. I hope it will help you in your study. I also hope you can support us to find the tutorial network.