Angular $ http.post报告失败,即使技术上它正在工作

时间:2014-04-06 19:40:46

标签: javascript angularjs

我有以下控制器:

function RegisterFormCtrl($scope, $http) {
    $scope.master = {};
    $scope.response = {};

$scope.update = function(reguser) {
    reguser.contactInfo.name = "MAIN";
    reguser.contactInfo.phone = "333-333-3333";
    reguser.contactInfo.address = "333 Elm St Indiana PA 15701";
    reguser.contactInfo.email = "someemail@johnson.com";
    reguser.name = "Joe Johnson";
    reguser.username = "joe.johnson";
    reguser.password1 = "abcDEF123-";
    reguser.password2 = "abcDEF123-";

    $scope.master = angular.copy(reguser);

    $http.post('http://imac.local:8080/api/register', reguser)
        .then(
            function(response) {
                console.log("SUCCESS");
                console.log(response);

            },
            function(response) {
                console.log("FAIL");
                console.log(response);

            });

};

当我触发更新方法时,$ http.post启动并在技术上起作用。意味着它会将正确的数据发送到我的服务器,服务器(restify)返回201并且Angular注册它。

请求标题:

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101         Firefox/28.0
Referer:    http://imac.local:8000/app/?
Pragma: no-cache
Origin: http://imac.local:8000
Host:   imac.local:8080
Content-Type:   application/json;charset=utf-8
Content-Length: 222
Connection: keep-alive
Cache-Control:  no-cache
Accept-Language:    en-US,en;q=0.5
Accept-Encoding:    gzip, deflate
Accept: application/json, text/plain, */*

响应标题:

Date:   Sun, 06 Apr 2014 19:21:16 GMT
Content-Type:   application/json
Content-Length: 333
Connection: keep-alive

结果:

Request URL:    http://imac.local:8080/api/register
Request Method:     POST
Status Code:    HTTP/1.1 201 Created

然而,失败方法被调用,"失败"得到打印,响应对象为空 有一点需要注意,服务器在同一台机器上的不同端口上运行: 客户:http://imac.local:8000 服务器:http://imac.local:8080

我提出来了,因为即使在本地使用相同的域,因为非原点故障,因为chrome不会在firefox中运行它。

就Angular / Node / JS而言,我已经大约3天了,所以任何帮助都会受到赞赏。

提前致谢。

0 个答案:

没有答案