Please be patient with me since I'm a beginner.
So I have this factory $http request to the server
$http request
factory.checkPollCodeIfAvail = function(x){
code = x;
return $http({
method: 'POST',
data: {
'action' : 'checkPollCode',
'pollCode' : code
},
url: 'http://localhost/poll/api.php',
transformRequest:function(obj) {
//transform header query into 'myVar1=var1Value&myVar2=var2Value'
var str=[];
for(var p in obj){
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]))
}
console.log(str.join("&"));
return str.join("&");
},
headers:{'Content-Type':'application/x-www-form-urlencoded'}
}).then(function(response){
var i = response.data.message.toString();
console.log(i);
return i;
});
};
which would supposedly return i to my controller:
Controller:
pollCodeStatus = pollFactory.checkPollCodeIfAvail('qwe123');
console.log(pollCodeStatus.toString());
when I try to console.log the i in the $http request i will get a value string but when I tried console.log in the controller what I will get is an object [object Object].
So can I convert an $http object to a string or even json data? if yes, how?
Thank you very much.