Export sharepoint list to json using jquery

1

I'm using sharepoint and would like to know if you have any way to export the sharepoint list to json, ie make ajax

    
asked by anonymous 30.10.2017 / 13:46

1 answer

0

Hello, you should create an HTML like this:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="RESTGetListItems.js"></script>
<div id="divListItems"></div>

And JavaScript like this:

$(function () {
retrieveListItems();});

function retrieveListItems() {var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var fullUrl = siteUrl + "/_api/web/lists/GetByTitle('Demo List')/items?$filter=Id ge 4";
$.ajax({
    url: fullUrl,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
    },
    success: onQuerySucceeded,
    error: onQueryFailed
});}

function onQuerySucceeded(data) {
var listItemInfo = '';

$.each(data.d.results, function (key, value) {
    listItemInfo += '<strong>ID: </strong> ' + value.Id +
        ' <strong>Title:</strong> ' + value.Title +
        '<br />';
});

$("#divListItems").html(listItemInfo);}



function onQueryFailed(sender, args) {
alert('Error!');}

    
16.02.2018 / 17:30