Upon receiving a JSON object from the server ({error:true}), I attempted to verify if the key "error" exists. Surprisingly, the function hasOwnProperty returned false.
Here is the snippet of code that led to this unexpected result:
$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);
});
Despite observing the presence of the "error" key in the object through the console output, the hasOwnProperty('error') check yielded false.