我正在从一些 ajax 操作中获取数据,并尝试使用 javascript 来实际进行一些条件检查
所以当我打印来自 ajax 的响应时
document.write(response)
结果
[object Object]
当我打印类似的东西时document.write(JSON.stringify(response))
结果
{"status":"failed","login":["This field is required."],"password":["This field is required."]}
所以上面是我得到的实际数据我想要做的是
if(response.status === 'failed')
window.location.href = response.next;
else if ('login' in response && response['login']==["This field is required."])
{
$("#message").html(<p>Username is required</p>);
}
else if ('password' in response && response['password']==["This field is required."])
{
$("#message").html(<p>Password is required</p>);
}
但是&&
条件response['login']==["This field is required."]
不起作用那么如何在 javascript 中检查上述类型的值?
注意:* JavaScript 新手*