how to show crud ajax error?

how to show crud ajax error?

kytankytan Posts: 6Questions: 3Answers: 0
edited April 2017 in Free community support

Hi, i am able to show my table but when i do an update using CRUD, if there is any error from update, which div do i show my error message?
do i show the error on div=DTE_Body? which div is the error div or what other to display errors on the bubble form?
thanks

editor = new $.fn.dataTable.Editor( {

        ajax: {
            create: {
                type: 'POST',
                url:  '../php/rest/create.php'
            },
            edit: {
                type: 'POST',
                'headers': {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                },

                error: function (jqXHR, textStatus, errorThrown) {                    
                    var errors = jQuery.parseJSON(jqXHR.responseText);
alert('data='+errors.message);
                    //console.log( 'An error has been reported by DataTables: ', errors.message );
                    $( '#error' ).html( errors.message );
                    console.log(errors.message);
                },
                url:  '/update_contact_detail/'
            },
            remove: {
                type: 'DELETE',
                url:  '../php/rest/remove.php?id=_id_'
            }
        },
        table: '#tbl_contact_list',
        fields: [
            { label: 'Phone', name: 'phone' },
            { label: 'Data',  name: 'data1'  },
            { label: 'Comment',  name: 'comment'  }
            
        ]
    } );

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Editor will automatically show any error messages that are in an error property in the returned JSON. If you aren't able to modify the returned JSON then you could use the error() API method to set the error message that Editor should show.

    You will need to put it in a small setTimeout() since Editor would otherwise immediately clear it (its callbacks run after the error callback, and if it doesn't see an error property in the JSON it will clear any previous error messages).

    Allan

  • kytankytan Posts: 6Questions: 3Answers: 0
    edited April 2017

    thanks

  • kytankytan Posts: 6Questions: 3Answers: 0

    How do i show message that the row has been successfully updated or deleted on the grid?

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Editor doesn't have a built in option for that. The default stylesheet while highlight the added row for around a second, while the deleted rows are just immediately removed.

    If you want to also show a message you would be best to listen for the submitComplete event and use that to show the message.

    Allan

This discussion has been closed.