I have ajax call to a function call "submit" the submit function is also run executor service for "doStuff" function.
it's return "ok" successfully in ajax complete condition, but I need to show the output from the executor service to the views when the process is finish. Is there any way to show the output of "doStuff" function ?
Try to return x inside "doStuff" function but it show an error
//views AJAX CALL
$("#formInput").submit(function (e) {
$("#submitFile").html("<i class='fa fa-circle-o-notch fa-spin'></i> Load..").prop("disabled", true);
$.ajax({
type: "POST",
url: "${local_server}/UploadController/submit",
data: new FormData(this),
processData: !1,
contentType: !1,
cache: !1,
dataType: "json",
complete: function (e) {
console.log(e);
if (e.responseText=="ok"){
//do();
}
}
});
e.preventDefault();
});
//Controller
@RequestMapping(value = "/submit", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String submitSurvey1(@ModelAttribute("uploadForm") UploadTest uploadForm, Model map,
HttpSession session, HttpServletRequest request) {
executor.submit(() -> doStuff(uploadForm,map,session,request)); // how I show this func output to views
return "ok"; // it's already return ok
}
private void doStuff(@ModelAttribute("uploadForm") UploadTest uploadForm, Model map,
HttpSession session, HttpServletRequest request){
token.regenToken(session);
String x = "";
JSONObject hit = new JSONObject();
hit.put("pathfile", "path");
hit.put("filename", "filename");
hit.put("submitted_by", session.getAttribute("session_id").toString());
JSONObject json = new JSONObject(new RestServiceUnirest().requestPost(
this.API + "/SubmissionLimit/uploadrecord/ec",
session.getAttribute("accesskey").toString(), hit.toString()));
x = json.toString(); //How I show this x in output
} catch (Exception e) {
file.delete();
x = e.getMessage();
}
}
}
}
}
}