Why does calling abort() on ajax request cause error in ASP.Net MVC (IE8)

Posted by user169867 on Stack Overflow See other posts from Stack Overflow or by user169867
Published on 2010-05-27T15:53:59Z Indexed on 2010/06/01 3:13 UTC
Read the original article Hit count: 441

Filed under:
|
|

I use jquery to post to an MVC controller action that returns a table of information. The user of the page triggers this by clicking on various links.

In the event the user decides to click a bunch of these links in quick succession I wanted to cancel any previous ajax request that may not have finished.

I've found that when I do this (although its fine from the client's POV) I will get errors on the web application saying that

"The parameters dictionary contains a null entry for parameter srtCol of non-nullable type 'System.Int32'"

Now the ajax post deffinately passes in all the parameters, and if I don't try and cancel the ajax request it works just fine.

But if I do cancel the request by calling abort() on the XMLHttpRequest object that ajax() returns before it finishes I get the error from ASP.Net MVC.

Example:

//Cancel any pevious request
if (req)
    {
        req.abort();
        req = null;
    }

//Make new request
    req= $.ajax({
          type: 'POST',
          url: "/Myapp/GetTbl",
          data: {srtCol: srt, view: viewID},
          success: OnSuccess,
          error: OnError,
          dataType: "html"
        });

I've noticed this only happen is IE8. In FF it seems to not cuase a problem.

Does anyone know how to cancel an ajax request in IE8 without causing errors for MVC?

Thanks for any help.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc