how to show crud ajax error?
how to show crud ajax error?
kytan
Posts: 6Questions: 3Answers: 0
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
This discussion has been closed.
Answers
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 theerror()
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 theerror
callback, and if it doesn't see anerror
property in the JSON it will clear any previous error messages).Allan
thanks
How do i show message that the row has been successfully updated or deleted on the grid?
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