I am developing an igGrid control on an existing ASP.NET application that uses forms authentication. The issue is when the client session times out (after 20 min of inactivity) and then tries to page/sort/filter, a javascript error is thrown: The remote request to fetch data has failed: (error) undefined
The response from the service is a 401 (unauthorized) with html content from IIS. It appears the grid is still trying to parse the response into JSON, even though there is an error in the response. NOTE: The same thing happens if the service sends back a 302 (redirect).
I tried digging through the 'dataBinding' event on igGrid to cancel the event and reroute to the login screen on a 401 error but I could not find the raw response.
I am wondering if there is a way to handle this case?
For the record, I am using version 2013.1, igGrid, igDataSource with remoteUrl, remote paging, remote sorting, and remote filtering. My url points to a Web Api OData service that returns JSON.
Thanks, Stamen.
The process was dying at the databind error. Adding the iggridrequesterror live event handler to return false allowed my redirect to work properly.
Hello Bertm13,There are a few ways you could handle the error codes coming from the server. The one I'll suggest is using jQuery's ajaxComplete function to assign a handler for all ajax calls. Your handler could look like this:
$(document).ajaxComplete(function (event, request, settings) { if (settings.url.startsWith($("#grid1").igGrid("option", "dataSource").settings.dataSource) && (request.status === 401 || request.status === 302)) { <your custom logic> }});
For the handler to be executed you have to disallow grid's binding errors by handling the requestError event and returning false:
$("#grid1").live("iggridrequesterror", function () { return false;});
I hope this helps!
Best regards,
Stamen Stoychev