开发者

"Object doesn't support this property or method" AJAX Error in IE 7,8 & 9

I've seen this error reported a few times, but have not come across a solution yet - here's my scenario.

I'm using an AJAX call which works perfectly in FF, Safari, Chrome & IE6. However in IE8, IE7 and IE9 I'm getting the following error, then the page just hangs on the AJAX loader .gif I have set up:

Line: 84
Char: 3
Error: Object doesn't support this property or method

The script in question seems to involve this:

function placeMarkers() {

if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
    var xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
    var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET","/maps/items.xml.php?childcare=<?php echo $_GET['childcare'];?>",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 
}

When I refresh the page in IE9 the script seems to work, but not when a search is performed using the form.

The line referred to in the error is:

 var xmlhttp=new XMLHttpRequest();
  • Just for your information, the XML file that the script 开发者_开发技巧opens, is generated with PHP because it is generated depending on a $_GET querystring.

  • ALSO, I have two other AJAX functions on the page, which both do the browser check as the one above does - not sure if this would cause a problem?

  • The website is built on a Wordpress installation.

  • The website includes JQuery and Google Maps API scripts (though I don't see how this could cause an issue?)

If anyone has any ideas, please let me know - this is all I need to fix to get a project complete. Also let me know if you need any more info, and I'll provide it.


After working all day on this, I was finally able to solve it - use Jquery AJAX rather than JavaScript. Unbelievably easier and much better supported. (thanks @mkilmanas)

Here's some really helpful tutorials I used:

http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/

http://www.xml.com/pub/a/2007/10/10/jquery-and-xml.html

http://www.vagrantradio.com/2009/10/how-to-parse-xml-using-jquery-and-ajax.html

http://api.jquery.com/jQuery.ajax

Basically, all JavaScript AJAX users, if you get this problem - the quickest way to get it working is to change your AJAX calls to JQuery and you'll have it working within minutes!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜