I keep getting this error, XML Parsing error: syntax error but still the website runs fine

I recently encountered the same issue. jQuery appeared to be handling the data and the dataType correctly, but instead it was Firefox returning the syntax error, which explains why your code was executing as intended but still printing an error to the console.

If you look in the developer console, you can see that Firefox is interpreting the plain text data as another format (likely XML). Firefox tires to parse the data as XML, but can't because it's not valid XML which results in "Syntax error" being printed to the console.

Fixing this problem for me involved editing the server so it returned the following header:

Content-Type: "text/plain"

This only appeared to be an issue with Firefox, Chrome did not encounter this issue. There is a Firefox bug here which seems to touch on the issue.

source


The problem still exists in Firefox 70, at least when requesting a file from the file system. No jquery needed, the behavior can be reproduced with a plain XMLHttpRequest. Calling its overrideMimeType method before send solved it for me. Looks like a quite clean solution to me. Example:

var xhr = new XMLHttpRequest();
xhr.open("GET", window.location, true);
xhr.overrideMimeType("text/html");
xhr.onreadystatechange = function()
{
    if (xhr.readyState == 4) alert(xhr.responseText);
}
xhr.send();