Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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 ESP8266未收到HTTPRequest_Javascript_Arduino_Esp8266 - Fatal编程技术网

Javascript ESP8266未收到HTTPRequest

Javascript ESP8266未收到HTTPRequest,javascript,arduino,esp8266,Javascript,Arduino,Esp8266,我似乎无法接收Javascript的HTTPRequest。我得到这个HTTP/1.1200ok 但我似乎无法获取发送过来的URL。我只想在我的网页上发送的链接 以下是我的javascript: jQuery(function($) {$("button").click(function(){ console.log(this.id); document.getElementById("direction").innerHTML = this.id + " is pressed.

我似乎无法接收Javascript的HTTPRequest。我得到这个
HTTP/1.1200ok
但我似乎无法获取发送过来的URL。我只想在我的网页上发送的链接

以下是我的javascript:

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:

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);

您只是从ESP上的index.php脚本中读取响应的第一行,这通常是您看到的HTTP状态代码,而不是其他代码(除非您还没有发布其他代码)。您需要读取整个HTTP消息以获得响应,特别是body-AssociationIndex.php使用body返回所需的数据。您可以在此处找到HTTP消息结构的描述: