我已经编写了一个AJAX脚本来读取数据库中的信息并将其作为HTML注入.php文件。它适用于IE8,Safari,Chrome而不是Firefox。没有显示错误或任何错误,它根本不会执行。AJAX脚本不能在Firefox中工作
下面的代码:
function queryDatabase(query)
{
alert();
var xmlhttp;
if (window.XMLHttpRequest)
{
alert();
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
alert();
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
content.innerHTML = xmlhttp.responseText;
}
else
{
content.innerHTML = "<center><span style=\"color: #ff7e00; font-size: 30px;\">LOADING...</div></center>";
}
}
xmlhttp.open("GET",query,true);
xmlhttp.send(null);
}
(警报是出于测试目的,但他们没有在Firefox中显示)
这里的div它的使用:
<div onClick="queryDatabase('latestquery.php')" style="cursor: pointer;">TEST</div> <div onClick="queryDatabase('testtagquery.php')" style="cursor: pointer;">TEST</div>
任何帮助表示赞赏:)
谢谢
山姆
只是一个有帮助的注释:我建议你去看看的jQuery(http://jquery.com) 。它可以帮助您避免所有浏览器特定的痛苦等等。 – BalusC 2009-11-07 20:45:38
如果您在'if(xmlhttp.readyState == 4){}'条件中添加了警报,您会看到它吗?如果这样做,结果显示可能会出现问题,而不是提取结果。 – nickd 2009-11-07 21:10:14