2016-04-03 70 views
0

我试图建立一个应用程序使用离子。我使用此代码跨源请求阻止与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错误。

有什么想法?

感谢

+1

当你在浏览器中测试,都是你的Ajax调用页面和API端点具有相同的域名,例如:http://本地主机: 8080? – shakib

+0

没有。我使用服务器端点 –

回答

0

你必须检查你的服务器,因为大多数使用的服务器的默认配置禁止跨来源资源共享(CORS)。

你可以阅读本网站的服务器进行配置:

http://enable-cors.org/server.html

+0

如果这是CORS问题,那么为什么我能够使用 http.post(链接,{用户名:$ scope.data.username,密码:$ scope.data.password})进行响应。 (function(res){scoped_response = res; }); –

+0

''scope.data.username,password:$ scope.data.password})''在你的设备中工作吗? – renyalvarado

+0

没有..在设备上没有任何工作 –

相关问题