I am calling a python script using AJAX call? I wish to perform some computation in Python which cannot be done in JS and return the result back to AJAX caller. Python script will just encode some data in JSON and send to AJAX caller.
But instead, when I have a return type of AJAX request as HTML or text, it just alerts entire python code instead of executing it.
How can I execute the Python code stored in my server instead of just accessing it?
I am sending the request as follows
$("#train").click(function () {
$.ajax({
type: "GET",
url: "<?php echo base_url('python/train.py'); ?>",
dataType: "json",
cache: false,
beforeSend: function() {
$('#train').val("Training Model...");
},
success: function(data) {
alert(data)
},
error: function(request, status, error) {
console.log("Error: " + error)
},
complete: function() {
$('#train').val("Trained Model")
}
});
});
Please help.