我已将问题区域缩小到以下功能.这是我写的用户脚本的一部分.它在Chrome中完美运行,但在Firefox/Greasemonkey中根本不起作用.我整天都在修补它并撞到了一堵砖墙.唯一有意义的是,如果JSON.parse不能正常工作,这是有道理的,因为已知Chrome处理JSON.parse有点不同......但我知道JSON完美形成!
function getTagline() {
var jsonfile = new XMLHttpRequest();
jsonfile.open("GET", "http://example.com/somegood.json", true);
jsonfile.onreadystatechange = function() {
if (jsonfile.readyState == 4) {
if (jsonfile.status == 200) {
var taglines = JSON.parse(jsonfile.responseText);
var choose = Math.floor(Math.random() * taglines.length);
var tagline = document.createTextNode(taglines[choose].metais);
insertTagline(tagline);
}
}
};
jsonfile.send(null);
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?