Question

I'm using the following code to request data from an ASP.net MVC application. I'm also using TcpTrace so that I can see the request/response.

if (isInteger($('#txtDay').val()) && isInteger($('#txtMonth').val()) && isInteger($('#txtYear').val())) {
    $.ajax({
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        url: strApi + 'wip/job/getsummary/' + $('#txtYear').val() + '/' + $('#txtMonth').val() + '/' + $('#txtDay').val(),
        data: '{}',
        dataType: 'json',
        cache: false,
        beforeSend: function(XMLHttpRequest) { ShowLoading(); },
        success: function(data, textStatus) {
            ShowJobSummaryList(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            HideLoading();
            ShowStatus('unable to retrieve job summary list');
            alert(XMLHttpRequest.statusText);
            alert(textStatus);
        },
        complete: function(XMLHttpRequest, textStatus) {
            HideLoading();
        }
    });
}

Using IE everything works fine - the content type is correctly set to application/json. However under Firefox 3.5.5, the content type is missing:

OPTIONS /api/wip/job/getsummary/2009/11/25 HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Origin: http://localhost
Access-Control-Request-Method: POST
Access-Control-Request-Headers: x-requested-with

This causes the ASP.net MVC to return XML. Can anyone explain why Firefox does not send the content type?

Was it helpful?

Solution

It looks like it is sending an options request. The normal cause of this issue is when your attempting to use make an ajax request to another domain which certain browsers (including firefox - see here) do not allow.

Can you clarify if the url your making the request to is on another domain. if this is the case you will have to use jsonp or use a server proxy.

OTHER TIPS

Similar thing is happening with me. When I fire the same request with Fiddler it works but when I fire it with Firefox HttpRequester, it doesn't. So I compared both the requests and it looks like HttpRequester changes the request headers. I tried several ways to get it to work, even edited the Raw request, but still when I check the final request the content-type is duplicated like so:

Content-Type: application/json, application/json

And it also adds a bunch of other headers. But when I checked the final request made by Fiddler it was just:

Content-Type: application/json

And hence it worked.

I also found reviews on Mozilla Firefox product support page complaining of similar bug. But I remember this worked before in HttpRequester so something to do with the latest version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top