I got a JSON object ({error:true}
) from the server.
I try to check if the object contains the key "error" and either the key exists, the function hasOwnProperty
returns false
.
This is my code:
$http({
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' },
url: '/Modules/Partners/Mailing/SendMail.ashx',
data: $.param({ contact: JSON.stringify(contact), body: partnerObject.mailTemplate.longValue, title: "" }),
method: 'POST'
})
.success(function (data, status, headers, config) {
console.log(data);
console.log(data.hasOwnProperty('error'));
if (data.hasOwnProperty('error')) {
deferred.reject(contact);
} else {
deferred.resolve(contact);
}
//console.log(data)
})
.error(function (data, status, headers, config) {
deferred.reject(contact);
});
In the console I can see that the object contains the "error" key by the hasOwnProperty('error')
returns false