So that's my code from website:
For json request:
Code: Select all
var xhttpData = new XMLHttpRequest();
xhttpData.open('POST', 'DATAJson', true);
xhttpData.setRequestHeader("Content-Type", "application/json");
xhttpData.onreadystatechange = function()
{
if (xhttpData.readyState === 4)
{
var DATAJson = xhttpData.response;
console.log(DATAJson)
}
}
xhttpData.send();
Code: Select all
var xhttp2 = new XMLHttpRequest();
xhttp2.open('POST', 'DATAJsonRecv', true);
xhttp2.setRequestHeader("Content-Type", "application/json");
xhttp2.onreadystatechange = function()
{
if (xhttp2.readyState === 4)
{
alert("Data sent");
}
}
xhttp2.send('{"JsonTestValue":5}');
Code: Select all
@app.route('/DATAJson')
async def index(request, response):
await response.send_file('data.json')
@app.route('/DATAJsonRecv')
async def index(request, response):
await print(request)
But when I simply write an address 192.168.4.1:8081/DATAJson i get the text of json in web browser. So I guess that code on ESP is correct.
When I try to send JSON to ESP I don't see any reaction.
What I'm doing wrong?