7

I am trying to GET list items from SharePoint 2013 using REST API and ajax call.It is returning by default ATOM+XML. I want the response in JSON format. I tried the following however still same XML format response:

"/_api/lists/getbytitle(ListName)/Items/?$filter=lookupName/LookupNameInSourceListName eq 'col_Name'&                   $select=LinkTitle,Image,lookupName/LookupNameInSourceListName&$expand=lookupName/LookupNameInSourceListName&$orderby=TabOrder asc"

 $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });
  • The question is opened again. Thanks for your cooperation ;-) – Benny Skogberg Jul 14 '14 at 15:13
14

Thanks for the answer: i tried no luck.

This one worked for me:

$.ajax({
    url: Url,
    method: 'GET',
    beforeSend: function (XMLHttpRequest) {                     
        XMLHttpRequest.setRequestHeader("Accept", "application/json; odata=verbose");
    },              
    cache: true,
    error: function (data) {                    ////failure     },              
    success: function (data) {                  ////success     }
});
  • Mark this as answer, if it is the solution to your problem. Thank you! – Benny Skogberg Jul 17 '14 at 8:00
  • This worked for me also! I tried the other three options (odata missing, or nometadata, or minimalmetadata) but only verbose worked... any idea why the other options are broken? is my sharepoint an older version? see blogs.office.com/2014/08/13/… – John Henckel Dec 29 '14 at 19:55
1

Add to your header:

"Content-Type": "application/json;odata=verbose"
1

Although already answered, the below worked too :

request.Accept = "application/json;odata=verbose";
request.ContentType = "application/json;odata=verbose";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.