此代码工作正常:
function callFromFlex(url, method, payload) {
console.log("call from Flex: " + method + " " + url + " " + payload);
var xhttp = new XMLHttpRequest();
xhttp.open(method, url, true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.onreadystatechange = function() {
console.log(xhttp.readyState);
if (xhttp.readyState == 4) {
console.log("trying to call flash...");
// Callback to Flash here
...
}
};
xhttp.send(payload);
}
但这不会 - 永远不会调用 onreadystatechange:
function callFromFlex(url, method, payload) {
console.log("call from Flex: " + method + " " + url + " " + payload);
var xhttp = new XMLHttpRequest();
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.onreadystatechange = function() {
console.log(xhttp.readyState);
if (xhttp.readyState == 4) {
console.log("trying to call flash...");
// Callback to Flash here;
...
}
};
xhttp.open(method, url, true);
xhttp.send(payload);
}
我只是将 xhttp.open(method, url, true) 移动到另一个位置,并且从未调用 xhttp.onreadystatechange。检查了 Firefox 45.0.2 和 IE 11,我相信它与 Flash 播放器无关。订单不应该影响这一切,不是吗?