Set the response header:
# Cross-origin domains are allowed. * indicates that all domains receive
Access-control-allow-origin: http://foo.example
# Methods that allow cross-origin execution
Access-control-allow-Methods: Post, get, options
# Header information that allows cross-origin settings
Access-control-allow-headers: X-PINGOTHER
The following is the nginx method
if ($ request_method = 'options ') {
add_header access-control-allow-origin *;
add_header access-control-allow-Credentials true;
add_header access-control-allow-methods 'get, post, options';
add_header 'access-control-allow-headers' 'DNT, x-Mx-reqtoken, keep-alive, User-Agent, X-requested-with, if-modified-since, cache-control, Content-Type ';
return 200;
}< br> if ($ request_method = 'post') {
Add_header 'access-control-allow-origin '*;
Add_header 'access-control-allow-Credentials ''true ';
Add_header 'access-control-allow-methods ''' get, post, options ';
Add_header 'access-control-allow-headers' DNT, X-Mx-reqtoken, keep-alive, User-Agent, X-requested-with, if-modified-since, cache-control, Content-Type ';
}
If ($ request_method = 'get '){
Add_header 'access-control-allow-origin '*;
Add_header 'access-control-allow-Credentials ''true ';
Add_header 'access-control-allow-methods ''' get, post, options ';
Add_header 'access-control-allow-headers' DNT, X-Mx-reqtoken, keep-alive, User-Agent, X-requested-with, if-modified-since, cache-control, Content-Type ';
}
Javascript: Call An Instance
Set the above configuration on nginx of dev.int. weishi. mobil. The website to which the Javascript page belongs is www.mongoach.com, and call the data on dev.int. weishi. Mobil through cross-origin post.
CallCodeYes
Postdata: function (data, success ){
VaR accounturl = "http://dev.int.weishi.mobi/web" + rpc. urluser;
VaR jsonuserinfo = $. tojson (data );
Jquery. Ajax ({
Type: 'post ',
Contenttype: 'application/json ',
URL: accounturl,
Data: jsonuserinfo,
Datatype: 'json ',
Success: function (data ){
If (data. Code = 0 ){
Success (data. Result );
} Else {
Alert (data. msg );
}
},
Error: function (data ){
Alert ("error ")
}
});
},