【问题标题】:ajax dont work in firefox [closed]ajax 在 Firefox 中不起作用 [关闭]
【发布时间】:2012-10-29 20:09:59
【问题描述】:

先生,有问题。我在codeigniter的mac系统上工作 此 ajax 代码适用于谷歌浏览器,但不适用于 Firefox 我的 Firefox 属性是 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.0.19) Gecko/2010031218 Firefox/3.0.19

<script>
function showUser(str)
{ 
    if (str=="")
    {
        document.getElementById("txtHint").innerHTML="";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    { 
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        { 
            // alert(xmlhttp.responseText);
            document.location.reload(true);

            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("POST","http://localhost/first_project/index.php/admin/selectUser/blank?q=" + str,true);
    xmlhttp.send();
}
</script>

请给我解决方案。 提前致谢。

【问题讨论】:

  • 控制台的错误信息是什么?
  • Firefox 3.0.19?您是否考虑过将其更新为 Firefox 16? :)
  • 看这里如何在jquery中使用更简单的ajax net.tutsplus.com/tutorials/javascript-ajax/…
  • @x3ro 有些人可能有要求,说明他们需要支持旧版浏览器,出于某些原因,有些公司使用旧版浏览器,例如 Firefox 3、IE7 等。
  • @JonTaylor 我知道有人想要支持旧浏览器(我自己一直在为古董 IE 版本优化一段时间),但他的问题是否反映了这样的要求?鉴于(对我而言)它没有,我建议更新。为什么我要对这样一个毫不费力地提出的问题花更多的心思,尤其是如果我不能确定他是否需要 Fx 3.0.19?

标签: php javascript codeigniter


【解决方案1】:

这毫无意义

        document.location.reload(true);  <-- reload the document

        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;  <--set text

当您重新加载文档时,有理由设置页面的文本。页面正在退出。如果要重新加载页面,为什么要发出 Ajax 请求?如果您要这样做,只需使用正常的表单提交即可。

更改函数以查看发生了什么

xmlhttp.onreadystatechange = function () { 
    if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) { 
            // alert(xmlhttp.responseText);
            document.location.reload(true);
            //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        } else {
            //console.error(xmlhttp.status + "\t" + xmlhttp.statusText);
            alert(xmlhttp.status + "\t" + xmlhttp.statusText);
        }
    }
};

【讨论】:

  • 没有 jQuery,因此你的答案很烂:)
猜你喜欢
  • 2013-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 2015-11-09
  • 2013-07-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多