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.
Read More:
- Solved: No’Access-Control-Allow-Origin’ cross-domain issue
- Solution to cross domain sharing problem of session
- Springboot plus cross domain annotation @crossorigin startup error
- How to solve the cross domain problem of Axios in Vue project
- Chrome setting — Disable web security to solve cross domain problems
- If the iframe in IE refers to the cross domain site page, the session fails
- In the HTML page request Ajax times 400 error, solve Yii submit post form 400 error, and Ajax post request 400 problem (example code)
- Domain error in object XXX “other” domain “other” rejected values and atm913
- Nginx configures different domain names to access different projects
- JS error: permission denied to access property ‘document’— document.domain -The same source strategy of JavaScript
- When to enter success and error in AJAX
- Django + jQuery get data in the form + Ajax send data
- Ant Design ‘cross env’ is not an internal or external command, nor is it an error reporting problem for a runnable program
- HTML method IE8 reports an error, IE8 jQuery Ajax obtains static resources reports an error, typeerror denies access
- Error: A cross-origin error was thrown. React doesn’t have access to the actual error object in deve
- A cross-origin error was thrown. React doesn‘t have access to the actual error object in development
- Ajax can’t download file to browser
- ajax error 400 (Failed to load resource: the server responded with a status of 400 (Bad Request))
- Encapsulation of Ajax JSON / fromdata request in native JS
- ImportError: cannot import name ‘cross_validation’ from ‘sklearn’