I have two questions regarding receiving of data when using XMLHttpRequest(). Client side is in javascript. Server side is in python.
- How do I receive/process data on the python side ?
- How do I respond back to HTTP request?
Client side
var http = new XMLHttpRequest();
var url = "receive_data.cgi";
var params = JSON.stringify(inventory_json);
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
UPDATE: I know i should use cgi.FieldStorage() but how exactly ?My attempt ended with me getting a Server error for the post request.