AngularJS 来自第一个响应的变量未传递给第二个请求?
AngularJS variable from first response not passed to second request?
我正在使用 Parse.com 作为后端,我需要发送 post 两次,第一次是 _User
class 和 customer
class . Customer
class 有 user_id
字段指向 _User.objectId
.
场景是我将 post 发送到 _User
获取 objectId,然后将 post 发送到 customer
其中包含 _User
objectId。
这是我的代码
$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);
});
以上代码结果成功插入2class,customer.user_id
未定义
我的代码是否遗漏或有问题?
您必须在第一个 http.post 请求的成功响应中写入第二个 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);
});
我正在使用 Parse.com 作为后端,我需要发送 post 两次,第一次是 _User
class 和 customer
class . Customer
class 有 user_id
字段指向 _User.objectId
.
场景是我将 post 发送到 _User
获取 objectId,然后将 post 发送到 customer
其中包含 _User
objectId。
这是我的代码
$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);
});
以上代码结果成功插入2class,customer.user_id
未定义
我的代码是否遗漏或有问题?
您必须在第一个 http.post 请求的成功响应中写入第二个 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);
});