Reference Documentation:
http://www.foreverpx.cn/2016/06/22/cross_content_type/
Problem:
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 does 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:
4.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.
4.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,
4.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.