Is there any way or tips to call a Python file (or functions) winthin a .js file (called on a HTML web page).
Indeed, I did the following tip : - configure my server (it's Apache) to run Python files (CGI) - created a Python file on the following structure :
print("<head>....</head>")
print("<body>....</body>")
But what I want is to call a Python file (a real one, with classes, functions or other things) on the Javascript. Any ways to do it ? (something with Ajax or other stuffs)
Thanks, Clément
EDIT
Here's what I want to achieve :
my structure :
1) HTML/CSS/JS files to create an interactive chat
2) a Python file to process the answers on the chat
My goal
On each post on the chat, a Javascript function of my .js file is called. This function need to run my Python file, and my Python file is supposed to return something. The Python file is a pure Python file, no HTML or other things.
What I've done
I created a server thanks to XAMPP. Moreover and as I said before, I tried the thing with print("...") on each line, but it's by far not what I want.
EDIT 2
I already tried a thing with AJAX like :
$(".mytext").on("keyup", function(e){
if (e.which == 13){
var text = $(this).val();
if (text !== ""){
insertChat("you", text);
$(this).val('');
$.ajax({
type: "POST",
url: "test.py"
});
}
}
});
but I get an error : The error I get is on the HTML console, in French :
Erreur d’analyse XML : mal formé
Emplacement : http://localhost/test/test.py
Numéro de ligne 1, Colonne 2
so in English:
Error of XML analysis : malformed
Path : http://localhost/test/test.py
Line 1, column 2