javascript - AJAX done() executed when finished all of request staff -
i have ajax request let user delete data list. when ajax done call ajax request list updated new list of data. ajax request delete data:
$.ajax({ method: "delete", url: urlrequest, headers: { 'x-csrf-token': $('meta[name="csrf-token"]').attr('content') } }).done(function() { console.log('removed'); // follow function call ajax request list updated new 1 ajaxrequesttogetnewdata(); }).fail(function() { console.log('fail'); })
the delete request above has lot of information delete, text , images , worried if ajaxrequesttogetnewdata()
called before server finishes of stuff.
my question: .done()
method safe above situation? if not, there other jquery method executed if request finishes of stuff?
yes, it's entirely safe.
the done()
handler not called until promise returned $.ajax
method has been resolved, happen after server has finished processing , returns 200 ok
response. if other response received fail()
handler execute instead.
in both cases server processing have stopped before response received client.
Comments
Post a Comment