How to use flask route only for calling a function and not redirecting in browser

Solution

$("#btn").click(function () { // assuming submit button as id btn
  $.ajax({
    type: "POST", //
    url: "/write_log", // url to the function
    data: {
      // include data here if you want to send something in json format
    },
    success: function (response) {
      $("#update_logger").html(response) // manipulate the dom
      localStorage.setItem("log", response);
    },
  });
});
if request.method == "POST":
   logger = upload.logger
   return logger