Created
September 6, 2017 14:16
-
-
Save mutuadavid93/fa58ca87955518c2760940c9dbfbf599 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get a SharePoint List Metadata for Use in REST API code. | |
1. Create a List and Add one item into it. | |
2. Create a SitePage and Insert a Script Editor into it. | |
3. Edit the WebPart to insert the code below inside. | |
4. Save the File. | |
5. Open Fiddler and inspect the Data from JSON tab. | |
6. You are good. | |
*/ | |
<div> | |
<div id="message"></div> | |
</div> | |
<script | |
src="https://code.jquery.com/jquery-2.2.4.min.js" | |
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" | |
crossorigin="anonymous"></script> | |
<script type="text/javascript"> | |
/* | |
Created on : Sep 6, 2017, 8:44:02 AM | |
Author : David Mutua | |
*/ | |
var queryFirst = function () { | |
var invokation = $.ajax({ | |
url : _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Demand')/Items", | |
type: "GET", | |
dataType: "json", | |
headers: { | |
Accept: "application/json;odata=verbose" | |
} | |
}); | |
invokation.done(function (data, textStatus, jqXHR) { | |
var message = $("#message"); | |
message.text(data.d.results.length); | |
}); | |
invokation.fail(function (jqXHR, textStatus, errorThrown) { | |
var response = JSON.parse(jqXHR.responseText); | |
var message = response ? response.error.message.value : textStatus; | |
alert("Call failed on CreateItem() Error: "+ message); | |
}); | |
}(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment