You can't use SimpleHTTPServer
for web-apps. It is not executing any code, it simply serves raw files (that's why you only managed to get the script text). I suggest using some web-framework; see this question.
Get data from python with ajax
-
31-05-2022 - |
Question
I'm passing data to a python script with ajax but I can't get that data back. The most I managed to get is 'undefined' or the script text itself (no idea why...). Currently, after a lot of tries, I get nothing.
I don't know if this is related but I'm new to python and didn't want to use any framework, so I'm using SimpleHTTPServer. Anyway...
This is the ajax call
$(function(){
$.ajax({
type: "GET",
url: "con-test.py",
dataType: "json",
success: function (responseText) {
alert(responseText); /* responseText.stuff is not working either */
}
});
});
And the script con-test.py
import json
result = {}
result['stuff'] = 'banana'
json_string = json.dumps(result)
print result # also tried return result
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow