I am trying to call a function in Python from my JavaScript code. I used the code explained here but it does not work for me.
Here is my JS code:
text ="xx";
$.ajax({
type: "POST",
url: "~/reverse_pca.py",
data: { param: text}
}).done(function(o) {
console.log(data);
console.log(text);
});
Python Code:
import csv
from numpy import genfromtxt
from numpy import matrix
def main():
...
return x
if __name__ == "__main__":
x=main()
return x;
Do you know what is wrong with it?
解决方案
Apart from the mentioned points and assuming you already have a proper setup to serve your python script and return the response. You should submit an asynchronous requ