I know this question has been asked before but I'm very confused, so sorry if the answer is already hear but I just need walking through
I want my JavaScript to my python script, pass two variables and then await a response of one variable. I know need ajax to do this. At the moment i have:
$.ajax({
type: "POST",
url: "/static/test.py", //location of python file
dataType: 'json',
data: {
choice: value //number variable i want to pass
equation: writteninput // string variable i want to pass
}
}).done(function(ans) {
finalanswer = ans // ans is the variable i want to
get back and finalanswer is
what i want to use in the rest
of my js
});
On my python side i know i need to use CGI to recieve the data however i have absolutely no clue how to do this. Here is my attempt so far:
import cgitb; cgitb.enable()
import cgi
import os
input_data = cgi.FieldStorage() #how do i get my two variables?
.....python does stuff......
print(ans) #ans is string
I've been stuck on this problem for a few days but due to me being new to programming I've been very confused. Any help is appreciated and thanks in advance.