-4

先生、何か問題があります。この ajax コードは google chrome で動作しますが、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>

解決策を教えてください。前もって感謝します。

4

1 に答える 1

4

これは意味がありません

        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);
        }
    }
};
于 2012-11-09T13:48:00.953 に答える