Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP AJAX无法执行';setrequestheader';在';xmlhttprequest';对象';必须打开服务器的状态_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript PHP AJAX无法执行';setrequestheader';在';xmlhttprequest';对象';必须打开服务器的状态

Javascript PHP AJAX无法执行';setrequestheader';在';xmlhttprequest';对象';必须打开服务器的状态,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我对AJAX有问题,我有一个错误: failed to execute 'setrequestheader' on 'xmlhttprequest' the object's state must be opened 我有这个密码: <script type="text/javascript" language="javascript">// <![CDATA[ var myRequest = null; function CreateXmlHttpReq


我对AJAX有问题,我有一个错误:

failed to execute 'setrequestheader' on 'xmlhttprequest' the object's state must be opened
我有这个密码:

<script type="text/javascript" language="javascript">// <![CDATA[

    var myRequest = null;

    function CreateXmlHttpReq(handler) {
      var xmlhttp = null;
      try {
            xmlhttp = new XMLHttpRequest();
      } catch(e) {
            try {
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e) {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
      }
      xmlhttp.onreadystatechange = handler;
      return xmlhttp;
    }
    // ]]>
</script>
<script type="text/javascript">// <![CDATA[

    function processa(messaggio,codiceChat){
            myRequest = CreateXmlHttpReq(stampa_chat); //apre la funzione appendi_province
            myRequest.open('POST','script/inviamessaggio.php'); //apre carica_province.php e gli indica che i valori passati devono essere considerati POST
            myRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); //indica che il contenuto di risposta sarà di tipo html-utf8
            myRequest.send("messaggio="+messaggio+"&chat="+codiceChat); //fa passare $_POST['regione']=valore al file carica_regione.php
            myRequest.setRequestHeader("connection", "close"); //chiude la connessione ajax
            alert(messaggio);
    }

    function stampa_chat(){
            if(myRequest.readyState==4 && myRequest.status==200){
                    var a=document.getElementById("chat");
                    a.innerHTML=document.getElementById("chat").innerHTML + myRequest.responseText; //stampa il contenuto html passato all'interno dell'elemento con id="provincia"
            }
    }
    // ]]>
</script>
//
// 
我在这个网站上搜索了一下,发现了这个问题:所以我尝试将->true参数添加到方法myrequest.open()中,但是没有…
我怎么了?我不知道我要做什么。。。我简直绝望了
谢谢大家,

Daniele

我认为您没有设置这个
:xmlhttp.setRequestHeader(“X-request-With”,“XMLHttpRequest”)


现在我也遇到了这个问题,但我已经解决了,原因是因为您在调用send后设置了一个标题…我试图按照您所说的切换位置,但我遇到了相同的错误。它只改变了车道!