So I have the function I want to call get_maps()
from a separate python file called "mapsinterpeter.py", and I have successfully requested the code, but I still cannot call the function.
function onSubmit(e) {
e.preventDefault()
if(year.value === "" || cat.value === "") {
msg.textContent = "Please fill out the fields"
msg.classList.add("error");
} else {
msg.textContent = ""
msg.classList.remove("error");
const catvalue = cat.value
$.ajax({
type: "POST",
url: "mapsinterpeter.py",
data: {async: false},
success: function (response) {
console.log(get_maps(/*args, ect */));
},
});
year.value = ""
cat.value = ""
}
}
Console:
get_maps is not defined
at Object.success (https://6534e288-58df-4278-82e3-7bfc760af484.id.repl.co/script.js:34:20)
at c (https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js:2:28327)
at Object.fireWith [as resolveWith] (https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js:2:29072)
at l (https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js:2:79901)
at XMLHttpRequest.<anonymous> (https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js:2:82355)
You can't call it directly from the javascript file
You have to call it and pass params from the AJAX call and then call the .done method when the API executes and do something with the values
$.ajax({
type: "POST",
url: "~/mapsinterpeter.py", // Change the path to match this
data: { param: text} // params for function
}).done(function( e ) {
// do something with function response
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.