views:

84

answers:

1

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

+2  A: 

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: http://stackoverflow.com/questions/1482177/problem-with-ie8-using-ajax.

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.

Matthew Crumley
Yeah? At first, I was using jQuery. Then, the debugger told me the problem was in the jquery.js file, in this area, approximately:xhr:A.XMLHttpRequest... And now I'm using regular javascript and it says the same? The same error and the same command? That cant be a coincidence?
Felipe Almeida
@Felipe: I searched for that error with XMLHttpRequest and found this question: http://stackoverflow.com/questions/1482177/problem-with-ie8-using-ajax. You could try the solution from there (it has a lot more code, but you can take out the part you need).
Matthew Crumley
thanks, I'll have a look
Felipe Almeida
Thanks Matthew. I dont really know why this works, but if you try and create the ActiveXObject("Msxml2.XMLHTTP"); object prior to creating the regular XMLHttpRequest it works. More info here http://www.daniweb.com/forums/thread299941.html ... and thanks again to Mathhew Crumley
Felipe Almeida