jquery - What is the best way to globally catch ajax errors in asp.net-mvc? -
i find myself putting (simplified) code in number of different javascript files:
$(document).ajaxerror(function (e, xhr, settings, exception) { alert('error in: ' + settings.url + ' \\n' + 'error:\\n' + exception + ": " + xhr.responsetext ); });
is there downside can think of putting in site.master file once have consistent solution errors?. if that, there anyway override behavior on specific page?
use $(document).ajaxerror
in site.master
file.
to override in specific instance, include error
callback on individual ajax calls, this:
$.ajax({ url: '/yoururl', success: function(result) { alert('it worked!'); }, error: function(xmlhttprequest, textstatus, errorthrown) { alert('your custom error message here.'); } });
for not want override, them omit error
callback.
Comments
Post a Comment