Javascript AJAX功能在IE中不起作用? [英] Javascript AJAX function not working in IE?

查看:113
本文介绍了Javascript AJAX功能在IE中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

function render_message(id)
{
var xmlHttp;
  xmlHttp=new XMLHttpRequest();  
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
        document.getElementById('message').innerHTML=xmlHttp.responseText;
        document.getElementById('message').style.display='';
        }
    }
    var url="include/javascript/message.php";
    url=url+"?q="+id;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

由于某种原因,它在IE中不起作用并且报告错误这一行document.getElementById('message')。innerHTML = xmlHttp.responseText; 未知运行时错误。

For some reason it does not work in IE and an error is being reported on this line "document.getElementById('message').innerHTML=xmlHttp.responseText;" with an "Unknown Runtime Error".

任何人都可以帮忙吗?

编辑:添加到div是有效代码等。

The code being added to the div is valid code ect.

以下是回复:

<div style="margin-left:auto;margin-right:auto;width:400px;">
    <img src="/forum/img/avatars/2.gif" width="90" height="89" style="float:left;">
    <div style="margin-left:100px;">
        <span style="font-size:16pt;">Sam152</a></span><br>
        <span style="font-size:10pt;text-transform:uppercase;font-weight:bold;">From Sam152</span><br>
        <span style="font-size:10pt;font-weight:bold;">Recieved April 17, 2009, 9:44 am</span><br>
        <br><br>

    </div>
</div>
<div style="margin-left:auto;margin-right:auto;width:400px;">
        asd</div>
<div style="margin-left:auto;margin-right:auto;width:400px;text-align:right;padding-top:10px;">
        <span onClick="requestPage('http://www.gametard.com/include/scripts/delete_message.php?id=14');document.getElementById('message14').style.display='none';document.getElementById('message').style.display='none';" class="button">Delete</span>
        <span onClick="document.getElementById('message').style.display='none';" class="button">Close</span>
        <span onClick="document.getElementById('to').value ='Sam152';document.getElementById('to').style.color ='#000';document.getElementById('newmessage').style.display='';" class="button">Reply</span>     

</div>


推荐答案

相信我:使用Ajax框架。

Trust me on this: use an Ajax framework.

jQuery或原型或任何其他。

jQuery or prototype or any of the others.

不要自己动手 - 你只看到这个问题的跨浏览器冰山一角。

Don't roll your own - you're only seeing the tip of the cross-browser iceberg with this issue.

如果你必须自己做,请检查 xmlHttp.status 在收到你的消息之前。请记住,IE有时会返回Windows错误代码而不是HTTP状态,如果错误是连接丢失而不是HTTP状态,则旧版FX会抛出异常。

If you must do it yourself check xmlHttp.status before getting your message. Bear in mind that IE sometimes returns Windows error codes instead of HTTP status here, and older FX throws an exception if the error is a lost connection rather than a HTTP status.

哦,IE6仍然占网络市场的30%左右,占公司市场的60%,所以@Paul Whelan的建议也值得一试。

Oh, and IE6 is still about 30% of the web market and 60% of the corporate one, so @Paul Whelan's advice is worth checking too.

这篇关于Javascript AJAX功能在IE中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆