我试图建立一个应用程序使用离子。我使用此代码跨源请求阻止与POST但工作正常与请求浏览器,但在设备上不工作
var req =
{
method: 'POST',
url: API_END_POINT + "/accounts/login",
data: this.toparams(myobject),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}
$http(req).
success(function(data, status, headers, config)
{
if(data.result = 'success') {
console.log('Success', data);
deferred.resolve(data);
} else {
deferred.resolve(0);
}
}).
error(function(data, status, headers, config)
{
console.error('ERR');
deferred.resolve(0);
});
return deferred.promise;
}
这是工作在浏览器上正常,但不能在设备..
即使我累了用这种方法
VAR链接= API_END_POINT +” /账户/登录“;
$http.post(link, {username : $scope.data.username,password:$scope.data.password}).then(function (res){
$scope.response = res;
});
这给我在浏览器上的CORS错误。
有什么想法?
感谢
当你在浏览器中测试,都是你的Ajax调用页面和API端点具有相同的域名,例如:http://本地主机: 8080? – shakib
没有。我使用服务器端点 –