mazlix
mazlix

Reputation: 6263

Set AJAX dataType using Vanilla javascript?

I am using some AJAX like this:

xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET","http://example.com",false);
    xmlhttp.send();
    data = xmlhttp.responseXML;

The xmlhttp.responseXML is returned in XML, so it's a javascript object. However, I would like it in raw string format. Something akin to setting dataType: "text" in jQuery's $.ajax()

Upvotes: 1

Views: 1844

Answers (1)

Joe
Joe

Reputation: 82554

Use responseText instead of responseXML

xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","http://example.com",false);
xmlhttp.send();
data = xmlhttp.responseText;

Upvotes: 4

Related Questions