Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular js 204 response blocking in IE10

NOTE: In reference to this website http://www.redbullracingshop.com.au/

I have a .net WebApi running along with angular $.http interaction on the front end. A client recently mentioned that the dynamic feature of the site have stopped working in IE.

After running the code in a few browsers and watching the requests. I noticed that in IE. The Post request were hanging or "pending" for about 2 minutes before returning a result to the client. I ran through the code with some break point on the server and the javascript to find where it was locking up, and found that the request fires fine and the server code executes as expected. Nothing is stalling here.

SERVER snippet

[AcceptVerbs("POST")]
public void AddToCart(JObject jsonData){
   // DO CODE
}

I am returning a void response, or 204. This is what i expect and don't consider this to be an error. Somewhere between the server responding and the client receiving the response, there is a 2 minute stall?

Is this an angular error maybe?

CLIENT snippet

this.post = function (url, data, success, fail) {
    fail = (fail !== undefined) ? fail : success;
    $http.post(url, data)
        .success(function (data) {
            if (data.length == 0) {
                success(onEmpty(url));
            } else {
                success(data);
            }
        })
        .error(function (data) {               
            fail(onError(url, data));
        });
}

I have investigated and found that this is only happening in IE10 and not actual version of the previous version, opposed to the emulated version from the dev console.

I am aware of IE doing some interesting stuff with 204 responses, and this might have changed in IE10. Se here https://github.com/angular/angular.js/issues/357?source=cc

The Network inspector results are as follows:

/api/CartApi/AddToCart | POST | 204 | 295 B | 384.76 s | XMLHttpRequest

Any Ideas? If all else fails i will have to try converting all these void WebAPI responses to empty strings maybe.

like image 868
Matthew.Lothian Avatar asked Jun 25 '13 02:06

Matthew.Lothian


1 Answers

For now the best solution I have is a work around. Don't use a void response resulting in a 204, instead return a manual HttpStatusCode.OK (200) response.

[AcceptVerbs("POST")]
public HttpResponseMessage AddToCart(JObject jsonData){
   // DO CODE
   return request.CreateResponse(HttpStatusCode.OK);
}

I am still curious for an explanation on this bug.

like image 65
Matthew.Lothian Avatar answered Nov 16 '22 01:11

Matthew.Lothian