问题
This is my code: (rather, the dodgy part thereof)
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var requisicao=new XMLHttpRequest();
} else {
var requisicao=new ActiveXObject("Microsoft.XMLHTTP");
}
Ok. Sometimes this works fine, but sometimes the Javascript Debugger in IE tells me this:
Object doesn't support this property or method model.js line 59 character 3
Which amounts to....
var requisicao=new XMLHttpRequest();
What bugs me is the fact that sometimes IE 8 accepts this and moves on but sometimes it chokes and doesn't work?
Any help is welcome
Thanks in advance
回答1:
Edit: Apparently, in this case, Internet Explorer's line number is correct. This seems to be a common problem with Internet Explorer 8. There's a potential solution here: Ajax app works in some browers, not others.
Here is the relevant part of the code:
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
Unfortunately, Internet Explorer's line numbers aren't always accurate, since they are based on its own, internal serialization of your code. The error message is probably coming from a different line (hopefully near line 59).
I would check for places where you are calling a method on an object that could be set to different values for whatever reason.
来源:https://stackoverflow.com/questions/3664462/ajax-inconsistency-in-ie-8