I am using the SharePoint 2010 REST API, which can return data in either xml or JSON format. For my scenario I need JSON.
Everything is working fine with jQuery:
$.ajax({
type:"GET",
url:url,
dataType:"json",
success: function(data, textStatus, jqXHR){...}
});
But I can't get JSON in plain JavaScript, the data is returned as xml. What am I missing?
var XHR=new XMLHttpRequest();
XHR.open("GET", url, true);
XHR.setRequestHeader("Content-Type","application/json");
XHR.onreadystatechange = function () {
if (XHR.readyState == 4 && XHR.status == 200) {...}};
XHR.send(null);
I believe that's a WCF oData service under the hood, which should respect the Accept
header.
var XHR=new XMLHttpRequest();
XHR.open("GET", url, true);
XHR.setRequestHeader("Accept","application/json");
XHR.onreadystatechange = function () {
if (XHR.readyState == 4 && XHR.status == 200) {...}};
XHR.send(null);
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