I'm fairly new using the jQuery controls, so maybe this is obvious, but I'm hoping someone can point me in the right direction. I have a simple grid that uses the DataSourceURL to asynchronously get data from the server and populate the grid. Most of the time, it works well. But I'm trying to find the right way to adapt when something goes wrong on the server-side during the ajax call.
Maybe the database timed out, maybe it's completely down, maybe the user doesn't have permission to view this data, maybe there's some other unexpected exception while trying to retrieve the data. It's easy enough to log the error and return no records. But, how do I tell the user what's going on? Especially for cases that aren't really an error, like users not having permission - I want to pass on an appropriate message.
By the way, I tried using the example here, but it looks like that won't work because it's not a js error, so ajaxSetup.Error and ajaxComplete never fire.
If it matters, I'm using Asp.Net MVC 4 with C#, Infragistics IgniteUI 13.1
Thanks for any suggestions you can give.
- Brad.
Hello visitraxnet ,
Thank you for your patience.
You can handle the request error event:
$(document).delegate("#grid1", 'iggridrequesterror', function (evt, ui) {
alert(ui.message);
return false;
});
And handle the error accordingly. The event will be triggered if there is an error in the request, when the grid is doing a remote operation like remote binding or remoter sorting/filtering/paging.
Let me know if you have any questions.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://es.infragistics.com/support
Definitely on the right track, but how do I get the error message? And, from your example, what is ui.message? In my test, it always returns "The remote request to fetch data has failed: (error) undefined", no matter what kind of error happens on the server. I'm testing by throwing a standard c# exception with a sample message "Database timeout, please try again" for now. I don't see that in either evt or ui properties.
The event is thrown for the errors raised by the grid. It will contain the information on the grid’s error that was raised which will be in this case that the remote request has failed since the server hasn’t returned any data. However it will not pass that internal server error message in its own error message.
If you want to get the whole response from the server you can use the ajaxError() handler. You can find more information on it here : http://api.jquery.com/ajaxError/#ajaxError-handlerevent--jqXHR--ajaxSettings--thrownError
In the jqXHR object there’s a response text property that will contain the whole text that the server has returned. You could find in it the exact error that the server has returned when an internal error occurs.