我在用着this and this参考,从函数内的 http 请求返回数据:
function getdetails(id) {
var datafordetails = {
data1: {
item1: "",
item2: ""
},
data2: {
item3: "",
ID: id
}
};
var jsonDataDetails = JSON.stringify(datafordetails);
return $http({
url: "http://...",
method: "POST",
data: jsonDataDetails,
dataType: "json",
timeout: 5000,
contentType: 'application/json; charset=utf-8'
})
.then(function (res) {
var data = res.data;
responsedata=data.d;
return responsedata;
},function (error) {
$scope.status = status;
console.log("Unable to update. No internet?");
})
}
我的目标是var testing = getdetails('12345');
给我那个 IS 的响应数据,但我正在返回Promise {$$state: Object...
我究竟做错了什么?多谢!
您得到的输出只不过是由返回的 Promise 对象$http.get
方法。基本上你需要把.then
功能结束getdetails2
用于从 Promise 对象获取数据的函数resolve
/reject
.
Code
getdetails2('12345').then(function(data){ //success callback
//you will get data here in data parameter of function,
var testing = data;
}, function(error){ //error callback
console.log(error)
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)