2016-11-18 8 views
0

私はバックエンドとしてParse.comを使用しています。まず、_Userクラスとcustomerクラスの2回投稿を送信する必要があります。 Customerクラスは_User.objectIdへのポインタuser_idフィールドを持っています。最初の応答のAngularJS変数は2番目の要求に渡されませんか?

私は_Userに投稿を送り、objectIdを取得し、_User objectIdを含むcustomerに投稿を送信します。ここで

は私のコード

$http.post('http://128.199.249.xxx:1337/parse/users', data, configRegister).then(function (response) { 
    console.log(response); 
    $scope.userObjectId = response.data.objectId; 
    console.log($scope.userObjectId); //succes print objectId 
}, function (error) { 
    alert(error.data.error); 
}); 


var dataProfileCustomer = { 
    user_id : { 
     __type: "Pointer", 
     className: "_User", 
     objectId: $scope.userObjectId //this part is not exist when I check in post request 
    }, 
    family_name: $scope.customer.family_name, 
    family_phone: $scope.customer.family_phone, 
    family_address: $scope.customer.family_address 
}; 

$http.post('http://128.199.249.xxx:1337/parse/classes/customer', dataProfileCustomer, configRegister).then(function (response) { 
    console.log(response.data); 
}, function (error) { 
    alert(error.data.error); 
}); 

上記のコードの結果が正常customer.user_idが定義されていない、2クラスに挿入しています。

コードに何か不足または間違いがありますか?

+0

最初のhttp.post要求の成功応答内に2番目のhttp.post要求コードを書き込む必要があります。 –

答えて

0

最初のhttp.post要求の成功応答内に2番目のhttp.post要求コードを書き込む必要があります。

$http.post('http://128.199.249.xxx:1337/parse/users', data, configRegister).then(
function (response) { 
    console.log(response); 
    $scope.userObjectId = response.data.objectId; 
    console.log($scope.userObjectId); //succes print objectId 

    var dataProfileCustomer = { 
     user_id : { 
      __type: "Pointer", 
      className: "_User", 
      objectId: $scope.userObjectId //this part is not exist when I check in post request 
     }, 
     family_name: $scope.customer.family_name, 
     family_phone: $scope.customer.family_phone, 
     family_address: $scope.customer.family_address 
    }; 
    $http.post('http://128.199.249.xxx:1337/parse/classes/customer', dataProfileCustomer, configRegister).then(
    function (response) { 
     console.log(response.data); 
    }, function (error) { 
     alert(error.data.error); 
    }); 


}, function (error) { 
    alert(error.data.error); 
}); 
関連する問題