返回json时出现arduino esp8266webserver错误

时间:2017-01-25 10:22:05

标签: jquery json arduino esp8266 arduino-esp8266

在我的arduino sketch中,我有这段代码:

void handleRoot() {
  server.send ( 200, "application/json", "{success:true,deviceID:'bla'}" );
}

所以我的arduino从我的wifi AP(192.168.0.100)获取ip,在我的js客户端代码中我有这个:

$.ajax({
  type: "POST",
  url: "http://192.168.0.100/",
  success: function(responseData) {
        alert(responseData);
},
});

但警报(responseData)甚至没有启动...... 我检查了浏览器控制台,我看到我得到了这个:

响应标题:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 29
Connection: close
Access-Control-Allow-Origin: *

在回复内容中我有这个:

{success:true,deviceID:'bla'}

为什么这些内容不会出现在警报中?

1 个答案:

答案 0 :(得分:0)

使用以下样本:

server.send(200, "text/plain", "{\"success\":1,\"deviceID\":\"bla\"}");

并在Ajax方面进行解析:

JSON.parse(responseData);
相关问题