question: Ajax cross-domain access error 501
Run the following code to make an 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 ("The Settings is OK.") The Machine is rebooting. ");
}
,
error:function (XHR, ajaxoptions, thrownerror) {
//on error do This
console.info ("error.");
if (Xhr.status =) {
alert (ajaxoptions);
}
else {
alert (xhr.status);
alert (thrownerror);
}
}
);
Workaround:
Remove contentType: ' Application/json; Charset=utf-8 '
Reason:
1 in the Cross-domain, in addition to ContentType for application/x-www-form-urlencoded, Multipart/form-data or text/plain outside, Triggers a request that the browser first sends the method to options.
2 For example, your original request was a method method post, and if the Allow attribute in the header returned by the first request does not have a post method,
3 So the second request is not sent, the browser console will be an error, telling you that the POST method is not supported by the server.
Reference Document: http://www.foreverpx.cn/2016/06/22/cross_content_type/
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.