AJAX inconsistency in IE 8?

浪子不回头ぞ 提交于 2019-12-12 04:19:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!