login.html:1 Failed to load http://larabbs.test/API/verificationCodes: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://test.im' is therefore not allowed access.
本地api服务器站点larabbs.test;另外本地创建了一个站点test.im,来访问larabbs.test的api接口,报错如下:
login.html:1 Failed to load http://larabbs.test/api/verificationCodes: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://test.im' is therefore not allowed access.
服务端env里这样设置的
API_STANDARDS_TREE=prs
API_SUBTYPE=WeAPP
我在js里这样写了
$.ajax({
url: 'http://larabbs.test/api/verificationCodes',
type: 'post',
headers: {
'Accept': 'application/prs.WeAPP.v1+json'
},
data: {
//获取用户填写手机号
phone: data.field.phone
},
success: function(data) {
console.log(data, 'success');
},
error: function(err) {
console.log(err, 'err');
},
complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
console.log(XMLHttpRequest, status, 'complete');
}
});
这是什么原因,应该怎么书写呢?
推荐文章: