-1

IE kept throwing "Unexpected call to method or property access" for no apparent reason.

Debbuging via console I've found out that it happens exactly after it reaches XDomainRequest.onload method, I have no idea what could be causing it, here's the code:

    var Xdr = new XDomainRequest(),
        _url = someurl;

    Xdr.open("get", _url);
    Xdr.onload = function () {
       var x = Xdr.responseText;
    };
    Xdr.onprogress = function(){ };
    Xdr.ontimeout = function(){ };
    Xdr.onerror = function () { };
    setTimeout(function(){
        Xdr.send();
    }, 0);

Any insights? It's just plain weird.

Carlos Yasuda
  • 121
  • 12
  • Your console is open right? do you see any requests happening either in the console or on your server? which line exactly does this error happen on? – Kevin B Feb 20 '15 at 19:20
  • The page loads perfectly when the console is open (ie debugs the error), otherwise it doesn't do anything besides wait for the response. The error happens on the exact first line of the Xdr.onload function – Carlos Yasuda Feb 20 '15 at 19:24
  • well there's your problem. console.log only works if the console is open. Welcome to IE Debugging! – Kevin B Feb 20 '15 at 19:25
  • Ahh sorry, I haven't made myself clear...I put the console just for the sake of example, not matter what I have there, it throws the "Unexpected call to method or property access", originally there's just a "var x = xdr.responseText", I'll edit the code. – Carlos Yasuda Feb 20 '15 at 19:29
  • If it happens on that line, does removing it remove the error? an error occurring on property assignment seems odd.. wondering if you may be misinterpreting something. – Kevin B Feb 20 '15 at 19:30
  • Now that I've seen it...it does not. Even if I leave the onload function empty, it still throws the error... – Carlos Yasuda Feb 20 '15 at 19:38
  • Doubt it matters, but.. in the msdn docs, it shows calling .open last, after setting up the events. https://msdn.microsoft.com/en-us/library/ie/cc288060%28v=vs.85%29.aspx – Kevin B Feb 20 '15 at 19:40
  • Nope, didn't do it =( – Carlos Yasuda Feb 20 '15 at 19:44
  • Are you running in compat/quirks mode? – Kevin B Feb 20 '15 at 19:45

1 Answers1

-1

You're missing a semi-colon on your first line of code.

Instead of:

var Xdr = new XDomainRequest(),

it should be:

var Xdr = new XDomainRequest();
securecodeninja
  • 2,497
  • 3
  • 16
  • 22