Home > Article > Backend Development > javascript - ajax cross-domain request problem
The php side has header("Access-Control-Allow-Origin:*");
ajax request
<code> $.ajax( { type : "post", url : url, async : false, dataType: 'json', data : {asdsa:1}, success : function (obj) { //业务代码 }, error : function (obj) { alert('未找到文件'); } } );</code>
If data is empty, for example {}, an error will be reported. The CORS header is missing 'Access-Control-Allow-Origin'
Data It’s normal to just write a parameter such as {dasdsa:1}. What’s going on?
This problem did not occur when cross-domain access was not bound to a domain name on the test machine, but now it does not work if the domain name is bound online
ps. There is a difference between testing and going online. Apache is used for testing the backend, and nginx is used for going online. Does this have anything to do with it?
The php side has header("Access-Control-Allow-Origin:*");
ajax request
<code> $.ajax( { type : "post", url : url, async : false, dataType: 'json', data : {asdsa:1}, success : function (obj) { //业务代码 }, error : function (obj) { alert('未找到文件'); } } );</code>
If data is shorted, for example {}, an error will be reported. The CORS header is missing 'Access-Control-Allow-Origin'
Data Just write a parameter such as {dasdsa:1} and it's normal. What's going on?
This problem did not occur when cross-domain access was not bound to a domain name on the test machine, but now it does not work if the domain name is bound online
ps. There is a difference between testing and going online. Apache is used for testing the backend, and nginx is used for the backend going online. Does this have anything to do with it?
I don’t know what you mean by cross-domain. Ajax can only operate within the root directory.
It feels like an ajax cache problem, and the cross-domain should be jsonp
Is it a server-side error or a client-side error reported in the network?