I have a localhost environment running using Python's SimpleHTTPServer, serving on port 8080.
My project consists of an HTML file, a python script, and a Javascript (vanilla) script.
The method I wish to employ is as follows:
- Click button in HTML
- Button fires Javascript AJAX request
- AJAX request runs Python script
- Python script produces JSON and returns it to Javascript
My JS is the following:
var json;
function trigger() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
json = xhttp.responseText;
console.log(json);
}
};
xhttp.open("GET", "./request.py", true);
xhttp.send();
}
Right now rather than seeing the output of a Python script I'm just seeing the content (as text) of the Python file.
I'm not sure of the correct AJAX call to RUN the .py script rather than just reading it and returning the contents.
Any help would be greatly appreciated!