Junk after document element. How to avoid XML parsing with ajax get (XMLHttpRequest) in vanilla javascript?

Viewed 1001

Firefox & AJAX Junk after document element

I'm having pretty much the exact same problem as the above question, but for different reasons.

To reiterate the problem:

I have some html file:

<style> #hat { color: red; } </style>
<script> var hat = "fez"; </script>

Which I'm retreiving via vanilla ajax call:

var request = new XMLHttpRequest();
request.open('GET', target, true);

request.onload = function() {
    if (request.status >= 200 && request.status < 400) {
        // Success!
        var response = request.responseText;
    } else {
        // We reached our target server, but it returned an error
    }
};

request.onerror = function() {
   // There was a connection error of some sort
};

request.send();

That is throwing an error in console:

junk after document element

I don't want the html file parsed at all. I've tried searching for a non XML HttpRequest method, but JQuery is all I can find on the subject. Perhaps there is something like a TextHttpRequest that just retrieves text without parsing it? Or maybe there's a way to tell an XMLHttpRequest that parsing is unnecessary?

This all seems like it should be pretty obvious, but I just keep finding tutorials on ajax that use jquery.

Here's a link to the MDN

1 Answers
Related