I'm trying to write a Javascript program which can get the return value of my Python program, I'm using Ajax. The connect between Js and Python succeeded, but when I use alert() function in Javascript to show what I got, It shows that it is always the whole Python code, not the return value I want. I tried several different Python programs, the returns are always the Python program itself. I need to get the return value, ({"a":"15","b":"17"} in this example).
Here is the Ajax part in Javascript:
$.ajax({
type: "get",
url: "http://localhost:8000/test.py",
data: {a:"15",b:"20"},
datatype: "json",
success: function(response){
var output = response;
alert(output);
//var getvalue = output.startdate;
//var xxx = parseInt(getvalue);
}
})
Here is the Python program:
import cgi, cgitb
import json
import sys
def TryAgain():
data = cgi.FieldStorage()
output = {"a":"15","b":"17"}
return output
Here is the running result on website: