4

このコードは正常に動作します:

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 Player とは関係ないと思います。注文はこれらすべてに影響を与えるべきではありませんよね?

4

1 に答える 1