views:

226

answers:

1

Hi,

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?

A: 

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.

redsquare
Thanks for the reply, however the request is to the same domain. In fact the page making the request and the ASP.net MVC app are on the same server.
markpirvine
It seems that a different port number also triggers this behavour in Firefox - I was viewing the html page over port 80, while using port 8080 (TCPTrace) to make the request to the ASP.net MVC app. Switched everything to 8080 at it worked!
markpirvine
yes, different port is considered x-domain!
redsquare