Last active
February 6, 2021 19:57
-
-
Save BishopKO/3bb9c393d9c22003f6ac21d5a0fc58ad to your computer and use it in GitHub Desktop.
ESP_ESP8266WiFi_Server_AJAX_response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void sendAJAXresponse(WiFiClient client, String message){ | |
String content_length_header = "Content-Length:"+String(message.length())+"\r\n"; | |
String answer = message + "\r\n"; | |
client.write("HTTP/1.1 200 OK\r\n"); | |
client.write("Content-Type:text/plain\r\n"); | |
client.write("Access-Control-Allow-Origin:*\r\n"); | |
client.write("Access-Control-Max-Age:600\r\n"); | |
client.write("Access-Control-Allow-Methods:PUT,POST,GET,OPTIONS\r\n"); | |
client.write("Access-Control-Allow-Headers:*\r\n"); | |
client.write(content_length_header.c_str()); | |
client.write("Connection:close\r\n\r\n"); | |
client.write(answer.c_str()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment