Ajax and internet explorer
Ajax and internet explorer
我有一段JavaScript代码,其中包含一个ajax请求,它打印出在IE8中无法工作的XML文件的内容。当我在谷歌上搜索这个问题时,我遇到了一些建议,我尝试了那些似乎与我正在尝试做的事情相关的建议。我在我的。htaccess文件中添加了以下行:我将overridemetype添加到我的代码中,并在我的xml文件的开头包含以下行:header('Content-type: text/xml')。这些对IE8中的输出没有任何影响,但是在XML文件中添加内容类型行使其在Firefox中无法工作。我想我一定是误解了内容类型行,所以我尝试将其包含在创建XML文件的php文件中。当我把它放在PHP文件的开头时,我得到了这个警告:警告:不能修改头信息-头已经发送了。我试着把创建XML文件的函数放在开头,但没有任何效果。我使用的代码在
下面<html>
<head>
<body>
<script type ="text/javascript">
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else //
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xhttp.overrideMimeType)
xhttp.overrideMimeType('text/xml')
xhttp.open("GET","captions_7.xml",false);
xhttp.send();
xmlDoc=xhttp.responseXML;
if(xmlDoc)
{
document.write("ok");
//in ie ok prints
}
else
{
document.write("failed");
}
elements = xmlDoc.getElementsByTagName("p");
length = elements.length;
for (var i=0; i<length ; i++)
{
//caption text
document.write(xmlDoc.getElementsByTagName("p")[i].childNodes[0].nodeValue + "<br />");
//start time
document.write(xmlDoc.getElementsByTagName("p")[i].getAttribute("begin")+ "<br />");
//end time
document.write(xmlDoc.getElementsByTagName("p")[i].getAttribute("end")+ "<br />");
}
</script>
</body>
</html>
在IE8中,这个文件的唯一输出是OK。在Firefox、Opera和Chrome中,将显示XML文件的内容。我在验证器中检查了XML文件,它没有报告错误,所以我认为这不是问题所在。我真的很感激,如果有人知道一个解决方案,或者有任何建议,我可以尝试。
如果它很重要,下面是创建xml文件的函数:
function createXML($referenceId){
header('Content-type: text/xml');
$content_id = $referenceId;
$XMLStart="<tt xml:lang='"en'"><head><layout/></head><body><div xml:id='"captions'">";
$XMLEnd = "</div></body></tt>";
$text;
$captionQuery = "SELECT caption_text, start_time, end_time FROM captions WHERE content_id = $content_id ORDER BY start_time ASC;";
$captionResult = mysql_query($captionQuery);
if(mysql_num_rows($captionResult)){
while($row = mysql_fetch_array($captionResult)){
$text.="<p begin='"".$row[start_time]."'" end='"".$row[end_time]."'">".$row[caption_text]."</p>";
}
}//end if
$XMLString = $XMLStart.$text.$XMLEnd;
$captionsFile="captions_".$content_id.".xml";
$captionsFileHandle = fopen($captionsFile, w) or die("can't open file");
fwrite($captionsFileHandle, $XMLString);
fclose($captionsFileHandle);
return $captionsFile;
}
我对这一切都很陌生,所以如果这是一个非常愚蠢的问题,我很抱歉。我想这一定是每天做成千上万次,但我就是不知道我能做些什么来解决它。 我强烈推荐使用jQuery的AJAX函数;它是跨浏览器兼容的,所以它应该有助于解决这个问题。
你的PHP函数是这样做的:创建一个xml文件(一个实际的文件),它写到磁盘。返回文件的名称。
你需要做的是:建立一个字符串的所有XML你想发送到客户端,回显该字符串
:
删除:
$captionsFile="captions_".$content_id.".xml";
$captionsFileHandle = fopen($captionsFile, w) or die("can't open file");
fwrite($captionsFileHandle, $XMLString);
fclose($captionsFileHandle);
return $captionsFile;
用
代替echo $XMLString;
这个问题可能与你是否使用jquery无关。
相关文章:
- 视频HTML没有'无法在Internet Explorer 11上工作
- Internet Explorer缺少占位符支持,特别是密码字段
- Internet Explorer中的文本换行错误
- 为什么我在Internet Explorer上看不到html元素
- internet explorer 8兼容模式下的Youtube api错误
- 当浏览器控制台未打开时,为什么要求会导致Internet Explorer 9超时
- Internet Explorer 8. Events
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- element.dataset in Internet Explorer
- Facebook FB.init”;访问被拒绝”;在Internet Explorer 11中
- JavaScript不适用于internet explorer和Firefox,但适用于谷歌
- 在Internet Explorer中,向所选内容添加选项不起作用
- 在Internet Explorer中从二进制文件打开PDF
- elementproblem internet explorer
- 我可以使用哪些方法在Internet Explorer中禁用Alt+*X*
- 如何在Internet Explorer中使用javascript设置cookie
- 只有当alert()在带有AJAX的internet explorer中使用时,Javascript才会更新UI
- sharepoint站点的internet explorer中出现Javascript错误
- Internet Explorer重新加载IFrame
- Internet Explorer Internet Failure HTTP Status Codes