【发布时间】:2017-10-13 20:16:50
【问题描述】:
这是我的js文件,下面的代码在.controller里面
xhr.onreadystatechange = function () {
if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200){
$http.post(smsHorizon,'Access-Control-Allow-Origin', '*').then(function(res){
res.addheader('Access-Control-Allow-Origin', '*');
res.addheader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.addheader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
if(res){
alert("OTP has been Send");
}
})
}
else{
}
}
这是编码cors的方法吗?请帮忙!!!
【问题讨论】:
-
你应该在服务器端添加标题
-
这是使用另一个 api 的服务器端代码
-
启用 CORS 的指南 - enable-cors.org
-
How to enable CORS in AngularJs 的可能重复项。
标签: angularjs angularjs-directive cors