I'm making an AJAX call to retrieve some plain text:
$.ajax({
url: "programData.txt",
type: "GET",
dataType: "text",
cache: false,
success: processData
});
When I make the request, though, I get the following error:
Error: not well-formed Source File: file:///projects/foo/programData.txt?_=1259694590361 Line: 1, Column: 2
Why is jQuery trying to process my plain text and how do I get it to stop?
Firefox is trying to parse the file as HTML before it even hands it back to jQuery.
There are several reasons why it could be trying to do this. If, as Jaanus suggested, you are using a file:// or chrome:// URL then it doesn't have a MIME type and it assumes HTML. Or your HTTP server could be returning the wrong MIME type.
Starting in jQuery 1.5.1 there is a mimeType option to override the returned MIME type that Firefox sees. So you can do the following:
$.ajax({
mimeType: 'text/plain; charset=x-user-defined',
url: "programData.txt",
type: "GET",
dataType: "text",
cache: false,
success: processData
});
Doc on mimeType option is at http://api.jquery.com/jQuery.ajax/
And here is some background on what is going on at the Firefox level: https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Receiving_binary_data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With