How can I catch error after ajax call?

How can I catch error after ajax call?

lucacali87lucacali87 Posts: 30Questions: 10Answers: 2
edited November 2015 in Free community support

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?

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015

    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

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    Yes, how can I format it?

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Instructions below the reply box..

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    thanks, I have updated the first post, I had misunderstood the meaning of "on newlines" :)

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Is it possible to catch error that I throw from java controller?

    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..

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    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

  • lucacali87lucacali87 Posts: 30Questions: 10Answers: 2

    nothing?

This discussion has been closed.