How to Call Python From Javascript?
Use ajax to Call Python From JavaScript
AJAX stands for Asynchronous JavaScript and XML. It utilizes the XMLHttpRequest object to communicate with servers.
It can send and receive information in numerous formats, including HTML, XML, JSON, and text files.
Example 1
$.ajax({
type: "POST",
url: "~/helloWorld.py",
data: {
param: "hello world",
}
}).done((o) => {
console.log(o)
});
Output
Thank you.
Example 2
$.getJSON('http://example.com/your/webservice?param1=x¶m2=y',
function(data, textStatus, jqXHR) {
alert(data);
}
)