How can I catch error after ajax call?
How can I catch error after ajax call?
lucacali87
Posts: 30Questions: 10Answers: 2
Hi, I'm using ajax call to retrieve information from my Spring controller but I would like to catch error if it occurs.
My actual code is:
if ( ! $.fn.DataTable.isDataTable( '#carsSelectionTable' ) ) {
carTable = $('#carsSelectionTable').DataTable({
select: {
style: 'single'
},
"ajax": "cars/" + selectedFleet,
"columns": [
{ "data": "idCar" },
{ "data": "id" },
{ "data": "initialKm" },
{ "data": "note" }
],
//hide id column
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
]
});
}
else {
carTable.ajax.url("cars/"+ selectedFleet).load();
Is it possible to catch error that I throw from java controller?
TableUI ajaxCall=new TableUI();
try {
ajaxCall.setData(fleetAndCarService.findCarsByIdFleetFetch(idFleet));
return ajaxCall;
} catch (QueryException e) {
//How do I do?
This discussion has been closed.
Answers
Is hard to read that code, its not formatted at all...
You can look at the replyStatus of settings.jqXHR, that will tell you what the last result was
Yes, how can I format it?
Instructions below the reply box..
thanks, I have updated the first post, I had misunderstood the meaning of "on newlines" :)
So the AJAX source for DataTables (javascript) is a Java app? And you want to catch something thats being thrown on the server side, within the client side code?
I dont think I understand what you're asking..
Generally I use web service to pass data to my hmtl or javascript. I use json with one error field that I check to control if one error occurred.
In datatables case, I call the above method to retrieve data through ajax call, but the json has only the field data without any another field that indicates one error. So in my javascript code I don't know if there was an error or less.
I don't know if I have explained myself better
nothing?