ajax
$.ajax({
type: 'post',
url: 'https://www.demo.com/?r=demo.php',
crossDomain:true, //跨域请求为true如果你想强制跨域请求(如JSONP形式)同一域,设置crossDomain为true。这使得例如,服务器端重定向到另一个域。默认为false
data: form_datas,
success: function (data) {
if (data.data!= undefined) {
alert('1');
}else{
alert('2')
}
}
})
nginx
location / {
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Headers $http_access_control_request_headers;
add_header Access-Control-Max-Age 3600;
add_header Access-Control-Allow-Credentials true;
}