Running CGI Python Javascript to retrieve JSON object -
i want use javascript retrieve json object python script ive tried using various methods of ajax , post cant working.
for have tried set this
my javascript portion: have tried
$.post('./cgi-bin/serverscript.py', { type: 'add'}, function(data) { console.log('posted: ' + data); });
and
$.ajax({ type:"post", url:"./cgi-bin/serverscript.py", data: {type: "add"}, success: function(o){ console.log(o); alert(o);} });
my python
import json
import cgi
import cgitb
cgitb.enable()
data = cgi.fieldstorage()req = data.getfirst("type")
print "content-type: application/json"
print (json.jsonencoder().encode({"status":"ok"}))
i getting 500 (internal server error)
have tried doing just
print (json.jsonencoder().encode({"status":"ok"}))
instead of printing content-type , blank line?
Comments
Post a Comment