I am facing an issue with displaying date in my Kendo UI grid. The data is coming from a Java servlet, and I have set the status code to 500 whenever an error occurs. Although I can see the error on the console, I am unable to handle it in JavaScript. My goal is to show a message to the user like 'Update failed because of xxx' or something similar. Below is my read code snippet (it always returns status 500 for testing purposes):
private void read(HttpServletRequest request, HttpServletResponse response) {
try {
DBOperations db = new DBOperations();
Gson _gson = new Gson();
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
System.out.println("Read called @" + sdf.format(cal.getTime())
+ " | p_callback: " + request.getParameter("callback"));
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(500);// For testing. Always return error!!!
response.getWriter().println(
(request.getParameter("callback") == null ? "callback"
: request.getParameter("callback"))
+ "("
+ _gson.toJson(db.getTrucksInPort()) + ")");
} catch (Exception e) {
e.printStackTrace();
}
}
Additionally, here is the JavaScript part in the HTML file:
<!DOCTYPE html>
<html lang="en">
// rest of the HTML content... (omitted for brevity)
</html>
The issue I'm facing is that when trying to display a message on the screen, nothing happens.
,errors:"Errors"
},
error:function(e){
alert("Failed!.");
this.cancelChanges();
}
I'm unsure where exactly I've gone wrong. Any help would be greatly appreciated. Thank you.