离子http发布到外部网址

Bet*_*eto 5 access-control http-post angularjs ionic-framework

我试图发送一个帖子到Ionic使用角度,但我有回应:

对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.原产地" 的http://本地主机:8100 "因此不允许访问.响应具有HTTP状态代码404.

我知道外部服务正在运行,因为我用ajax测试它,一切都运行完美......

在AngularJS(Ionic)和Ajax中使用的代码下面:

离子型:

var loginServiceUrl = 'http://url.com.br'; //It is not the real one
var loginServiceData = {
    email: email@email.com.br
    senha: 1234
};
$http.post(loginServiceUrl, loginServiceData).
then(function (res){
    console.log(res);
});
Run Code Online (Sandbox Code Playgroud)

阿贾克斯:

$.ajax({
    type: "POST",
    url : 'http://url.com.br', //It is not the real one
    data : {email: 'email@email.com.br', senha: '1234'},
    success: function(result) {
        $('html').text(JSON.stringify(result));
    }
});
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我通过我的localhost上的ajax获取帖子而不是离子,也是localhost?

rad*_*tiv 1

看一下这个。它很好地解释了如何处理像你这样的问题 --> http://blog.ionic.io/handling-cors-issues-in-ionic/