With JS, i send a AJAX post request.
$.ajax(
{method:"POST",
url:"https://my/website/send_data.py",
data:JSON.stringify(data),
contentType: 'application/json;charset=UTF-8'
On my Apache2 mod_Python server, I wish for my python file to access data
. How can i do this?
def index(req):
# data = ??
PS: here is how to reproduce the problem. Create testjson.html
:
<script type="text/javascript">
xhr = new XMLHttpRequest();
xhr.open("POST", "testjson.py");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function(res) { console.log(xhr.responseText); };
xhr.send(JSON.stringify({'foo': '0', 'bar': '1'}));
</script>
and create testjson.py
containing:
from mod_python import apache
def index(req):
req.content_type = "application/json"
req.write("hello")
data = req.read()
return apache.OK
Create a .htaccess
containing:
AddHandler mod_python .py
PythonHandler mod_python.publisher
Here is the result:
testjson.html:10 POST http://localhost/test_py/testjson.py 501 (Not Implemented)