I'm trying to do a REST call to get current user information without using jQuery to handle the ajax. I've got this code:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == XMLHttpRequest.DONE){
if(xmlhttp.status == 200){
console.log(JSON.parse(xmlhttp.responseText))
} else if (xmlhttp.status == 400){
console.log("not found")
} else {
console.log("other")
}
}
}
xmlhttp.responseType="json"
xmlhttp.open("GET","https://,site/_api/web/currentuser?$format=json",true);
xmlhttp.send()
This works, but the response comes back as xml not json. Is there a way to tell the SP to return json when using XHR?
I tried the $format=json
parameter, but that evidently isn't supported by the SP 2013 REST api. Nor is XMLHttpRequest.responseType supported by browsers.