“对象不支持此属性或方法” IE 7,8 和 IE 中的 AJAX 错误9
我已经多次看到此错误报告,但尚未找到解决方案 - 这是我的情况。
我正在使用 AJAX 调用,该调用在 FF、Safari、Chrome 和 Chrome 中完美运行。 IE6。然而,在 IE8、IE7 和 IE9 中,我收到以下错误,然后页面只是挂在我设置的 AJAX 加载器 .gif 上:
Line: 84
Char: 3
Error: Object doesn't support this property or method
有问题的脚本似乎涉及此:
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;
}
当我在 IE9 中刷新页面时,脚本似乎工作,但在使用表单执行搜索时不起作用。
错误中引用的行是:
var xmlhttp=new XMLHttpRequest();
仅供您参考,脚本打开的 XML 文件是使用 PHP 生成的,因为它是根据 $_GET 查询字符串生成的。
另外,我在页面上还有另外两个 AJAX 函数,它们都像上面的函数一样进行浏览器检查 - 不确定这是否会导致问题?
该网站是在 WordPress 安装上构建的。
该网站包含 JQuery 和 Google Maps API 脚本(尽管我不明白这会如何导致问题?)
如果有人有任何想法,请告诉我 - 这就是我需要修复才能完成项目的全部内容。如果您需要更多信息,请告诉我,我会提供。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一整天的努力,我终于能够解决它 - 使用 Jquery AJAX 而不是 JavaScript。令人难以置信的简单和更好的支持。 (感谢@mkilmanas)
这是我使用的一些非常有用的教程:
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
基本上,所有 JavaScript AJAX 用户,如果您遇到此问题 - 让它工作的最快方法是将您的 AJAX 调用更改为JQuery,几分钟之内你就能让它工作了!
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!