1.为ajax增加属性,允许跨域请求:
xhrFields: {
withCredentials: true
},
crossDomain: true,
2.请求地址的head里面加上Access-Control-Allow-Origin,值设置成调用该API的域名(或者*),为ajax增加属性:
beforeSend:function(xhr){
xhr.setRequestHeader('Access-Control-Allow-Origin','http://baidu.com/');
},