Hi Ionites,
I am having difficulty in using transformRequest inside my http.post but when I use it globally it magically works well. What am i missing??
Global transformRequest code
var serialize = function(obj, prefix) {
var str = [];
for(var p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}
// send all requests payload as query string
$httpProvider.defaults.transformRequest = function(data){
if (data === undefined) {
return data;
}
return serialize(data);
};
Http Post code:
$http.post("https://www.colombiandreamdate.com/api/v1/addfavorites", {
transformRequest: serialize(data),
data: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
.success(function (response) {
})
.error(function (response) {
});