2016-03-20 8 views
0

JavascriptのHTTPRequestを受信できないようです。私はこれを得るHTTP/1.1 200 OK しかし、私は上に送信されたURLを取得するように見えることはできません。私は私のウェブページ上に送信しているリンクを望んでいます。空ループでESP8266はHTTPRequestを受信しません

jQuery(function($) {$("button").click(function(){ 
    console.log(this.id); 
    document.getElementById("direction").innerHTML = this.id + " is pressed."; 

    newurl = 'index.php?btn='+ this.id+"?key="+user.key; 
    sendHttpRequest(newurl); 
    }); 
}); 

function sendHttpRequest(update){ 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
     if (xhttp.readyState == 4 && xhttp.status == 200) { 
      console.log(xhttp.responseText); 
     } 
    } 
    xhttp.open("GET",update,true); 
    xhttp.send(null); 

    console.log(update); 
} 

ESP8266:ここ

は私のjavascriptのあるあなたが唯一のESP、上のindex.phpスクリプトからの応答の最初の行を読んでいる

WiFiClient client; 
String url = "/index.php?"; 

client.print(String("GET ") + url + " HTTP/1.1\r\n" + 
      "Host: " + host + "\r\n" + 
      "Connection: close\r\n\r\n"); 
    Serial.println("Request Sent"); 


    String request = client.readStringUntil('\r'); 
    Serial.println("headers received"); 
    Serial.println(request); 

答えて

0

ました一般にあなたが見ているHTTPステータスコードであり、他に何もありません(投稿していない他のコードがない限り)。レスポンス、特に本文を取得するには、HTTPメッセージ全体を読む必要があります。index.phpが本文を使用して必要なデータを返すと仮定します。ここにHTTPメッセージ構造の説明があります:https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html

関連する問題