24s*_*ron 1 javascript json http angularjs
{error:true}我从服务器获得了一个 JSON 对象 ( )。
我尝试检查对象是否包含键“error”,并且键存在,函数 hasOwnProperty 返回false。
这是我的代码:
$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);
});
Run Code Online (Sandbox Code Playgroud)
在控制台中,我可以看到该对象包含返回的“error”hasOwnProperty('error')键false
| 归档时间: |
|
| 查看次数: |
12657 次 |
| 最近记录: |