AngularJS 发布请求无法正确获得服务器响应



我正在使用AppGyver Steroids和AngularJS开发一个混合移动应用程序。在这个移动应用程序中,我需要使用我开发的另一个项目的 RESTful API;以下是我从移动应用程序发送的示例请求:

var data = {
    'email': $scope.userEmail,
    'password': $scope.userPassword
}
$http.post('http://example.com/api-auth-token/?format=json', data)
    .success(function(data, status, headers, config) {
        alert(data);
        $location.path('/profile');
    })
    .error(function(data, status, headers, config) {
        // show error details
        navigator.notification.alert(
            'Authentication failed. (' + status + ')',
            null,
            'Error',
            'Okay'
        );
    });

此请求可以很好地到达服务器,并且生成状态代码为 200 的有效响应......至少当我检查服务器日志时是这种情况。移动应用程序显示一个消息框,指出"身份验证失败。(404)",这与服务器日志所述内容相矛盾。

编辑:我还开发了一个使用这些API的本机iOS应用程序,它可以毫无问题地工作。

事实证明,服务器生成的响应中缺少访问控制允许源标头,这是罪魁祸首。

最新更新