JSON 响应 parsed/not 已针对 Chrome 和 IE 进行解析
JSON response parsed/not parsed for Chrome and IE
XMLhttpRequest returns JSON 与
abc.responseType = 'json';
var answer = abc.response;
如果我执行以下操作,它将在 chrome 中工作:
if (answer.success) {
window.alert("GOODBOY!");
} else {
window.alert("YOUFAILED" + answer.message);
}
但是,IE 总是会跳过 if
,即使 success
是 true
为了让它在 Internet Explorer 中工作,我尝试解析它(再次?)
var answer = abc.response;
var answer2 = JSON.parse(abc.response);
if (answer2.success) {
window.alert("GOODBOY!");
} else {
window.alert("YOUFAILED" + answer2.message);
}
在 IE 中有效,但在 chrome 中显然会导致以下错误:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
我错过了什么?我怎样才能让它在两种浏览器上工作?
由于 IE 不支持 json
作为 responseType
,放弃它,使用默认的 text
并执行
var answer = JSON.parse(abc.response);
XMLhttpRequest returns JSON 与
abc.responseType = 'json';
var answer = abc.response;
如果我执行以下操作,它将在 chrome 中工作:
if (answer.success) {
window.alert("GOODBOY!");
} else {
window.alert("YOUFAILED" + answer.message);
}
但是,IE 总是会跳过 if
,即使 success
是 true
为了让它在 Internet Explorer 中工作,我尝试解析它(再次?)
var answer = abc.response;
var answer2 = JSON.parse(abc.response);
if (answer2.success) {
window.alert("GOODBOY!");
} else {
window.alert("YOUFAILED" + answer2.message);
}
在 IE 中有效,但在 chrome 中显然会导致以下错误:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
我错过了什么?我怎样才能让它在两种浏览器上工作?
由于 IE 不支持 json
作为 responseType
,放弃它,使用默认的 text
并执行
var answer = JSON.parse(abc.response);