jQuery ajax() function is ignoring dataType parameter in Firefox

Posted by ccleve on Stack Overflow See other posts from Stack Overflow or by ccleve
Published on 2013-07-02T16:38:55Z Indexed on 2013/07/02 17:05 UTC
Read the original article Hit count: 442

Filed under:
|
|
|
|

I'm trying to use jQuery.ajax() to fetch some html, but Firefox is giving me a "junk after document element" error message. As explained here and here the problem seems to be that Firefox is expecting XML from the server, and when it doesn't parse correctly it throws the error. Here's my ajax code:

    jQuery.ajax({
        url: name,
        dataType: "html",
        success: function(result) {
            console.log(result);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log(errorThrown);
        }
   });

The server returns the html with these response headers:

Accept-Ranges   bytes
Content-Length  2957
Last-Modified   Tue, 02 Jul 2013 16:16:59 GMT

Note that there's no content-type header. I'm sure that adding one would solve the problem, but that's not an option.

The real problem is that Firefox appears to be ignoring the dataType: parameter in the ajax call. I've also tried adding contentType: and accepts: parameters, but it doesn't help.

What am I missing here? How do I force Firefox to process the response as plain text?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery