Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
Handling 401 and 302 status codes
posted

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.

Parents
  • 5513
    Verified Answer
    Offline posted

    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

Reply Children
No Data