AJAX inconsistency in IE 8?

This is my code: (rather, its tricky part)

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:

The object does not support this property or the model.js method line 59 character 3

Which is ....

 var requisicao=new XMLHttpRequest(); 

What bothers me is that sometimes IE 8 takes it and moves on, but sometimes it suffocates and doesn't work?

Any help is appreciated

Thank you in advance

0
source share
1 answer

Edit: It looks like the line number in Internet Explorer is correct in this case. This is apparently a common problem with Internet Explorer 8. There is a potential solution here: Ajax works in some browsers, not in others .

Here is the relevant piece of 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, the line numbers in Internet Explorer are not always accurate, as they are based on your own internal serialization of your code. The error message probably comes from another line (hopefully near line 59).

I would check the places where you call the method on an object, which for any reason can be set to different values.

+2
source

All Articles