I'm using this and this reference, to return data from an http-request inside a function:
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?");
})
}
My goal is that var testing = getdetails('12345');
gives me the responsedata for that ID, but I'm getting back Promise {$$state: Object...
What am I doing wrong? Thanks a lot!