jQuery serializeArray + ajax.post IE (only) occasionally does not pass form elements to ashx Handler

StackOverflow https://stackoverflow.com/questions/12323510

Pergunta

My .ashx Handler called from a jQuery AJAX post occasionally does not receive form elements in the HttpContext.Request.

When this happens, the Request contains either only ViewState elements or has no elements at all.

It has failed OCCASIONALLY only with IE7, IE8, and IE9 (with several thousand hits/day by various browsers). I cannot reproduce this myself using IE and 'most' IE users (and all other users) do not experience this problem.

Javascript:

var data = $('form').serializeArray();
$.ajax({
            type: "POST",
            async: false,
            dataType: "text",
            url: "handler.ashx",
            data: data
        });

C# (handler.ashx):

void IHttpHandler.ProcessRequest(HttpContext context) {
     var collection = SetCollection(context.Request);

     // collection sometimes has just ViewState elements;
     // sometimes it has no items
     }

private NameValueCollection SetCollection(HttpRequest request){
    return request.Form;
}

Other info: The site is part of a web farm with a load balancer. Using .net 3.5. I read that IE has a different way of generating the request header; not sure if this is related.

Thank you for any insight to resolving my problem.

Foi útil?

Solução

FIXED: This problem was existing in Firefox as well which helped resolve the problem because I could use Firebug.

This handler was built to post information to the server and throw a server exception if there are any errors (i.e. javascript needed no response). Firefox and IE expect a response back to javascript; Firefox fails gracefully (throwing a server error but still working); IE fails nastily by crashing the browser.

I added a context.Response.write("true") to the end of the handler and it no longer throws errors or dies.

Hope this helps someone else down the road.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top