簡體   English   中英

服務器未使用get方法響應xmlHTTP請求

[英]Server doesn't respond to an xmlHTTP request using the get method

我正在與arduino進行一個項目,在該項目中,我使用XMLHttprequest和從網頁中獲取方法將不同的請求發送到服務器(arduino板)。 除了其中一個請求,其他請求僅用於向服務器發送訂單,因此我不希望XML響應。 另一個是每隔5秒發送一次的請求,用於從服務器獲取不同的值。

最后一個問題來了。 實際上,該網頁每5秒鍾發送一次請求(因為我在瀏覽器控制台和arduino串行監視器上看到了該請求),但是它什么也沒收到,只是答案的頭確認了響應,但與XML文件無關。 出乎意料的是,當我在瀏覽器中使用get方法編寫普通請求時,我立即獲得了帶有值的XML文件,而且我一直這樣做。

我要寫我在網頁上使用的javascript代碼

setInterval(function tiempo()
{
    var request = new XMLHttpRequest();
    request.onreadystatechange = function()
    {
        if (this.readyState == 4) {
            if (this.status == 200) {
                if (this.responseXML != null) {
//                  extract XML data from XML file (containing switch states and analog value)
                    document.getElementById("input1").innerHTML = this.responseXML.getElementsByTagName('dato')[0].childNodes[0].nodeValue;
                    document.getElementById("input2").innerHTML = this.responseXML.getElementsByTagName('dato')[1].childNodes[0].nodeValue;
                    document.getElementById("input3").innerHTML = this.responseXML.getElementsByTagName('dato')[2].childNodes[0].nodeValue;
                    document.getElementById("input4").innerHTML = this.responseXML.getElementsByTagName('dato')[3].childNodes[0].nodeValue;
                    document.getElementById("input5").innerHTML = this.responseXML.getElementsByTagName('dato')[4].childNodes[0].nodeValue;
                    document.getElementById("input6").innerHTML = this.responseXML.getElementsByTagName('dato')[5].childNodes[0].nodeValue;
                    document.getElementById("input7").innerHTML = this.responseXML.getElementsByTagName('dato')[6].childNodes[0].nodeValue;
                }
            }
        }
    }
    request.open("GET", "URL" + Math.random(), true);
    request.send(null);
}
, 5000);

另一方面,如果僅在瀏覽器URL編寫,則可以毫無問題地獲取XML。

我要說的一件事是,現在我正在使用存儲在計算機中的網頁,但是在使用存儲在arduino(SD卡中)並通過arduino通過互聯網加載的網頁之前。 在這種情況下,相同的代碼可以完美地工作。 我改變的原因是因為arduino以太網不太快,並且花費了很多時間。 隨着網頁存儲在我的計算機中,它運行得更快,因為它只需要發送訂單即可。

謝謝!!

最后,我找出了問題所在。 它是瀏覽器。 出於任何原因,只有Internet Explorer才能正確處理該網頁。 firefox和其他Web瀏覽器都未獲取xml文件。 我不知道原因,但我想找到它。

如果有人知道有關我的信息,我將很樂意嘗試解決問題。

謝謝!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM