我想区分服务器响应、基于 json 的或纯文本。所以在我的ajax调用中我有:
success: function(resp) {
//
json = $.parseJSON(resp);
if (typeof json == "object") {
console.dir(json);
} else {
console.dir(resp);
}
//
}
问题是,它在 Parse 行上中断,所以我永远无法到达我检查 typeof 的行...
Uncaught SyntaxError: Unexpected token
我究竟做错了什么?
ps resp 有时是 json,有时是纯文本。