Learn how to create list item in SharePoint 2013 using REST interface. This blog will help you to learn REST API basics and how that works in SharePoint.
Steps
- Edit your SharePoint page and a Content Editor webpart.
- Copy the below code and save it as txt format in your site assets library.
- Get the txt file link and give it in the CEWP.
- Click the createlist button .
That's it.
- <script type="text/javascript" src="https://gowthamr.sharepoint.com/sites/Test1/SiteAssets/jquery.min.js"></script>
-
- <script type="text/javascript">
-
- $(document).ready(function(){
-
-
- $("#btnClick").click(function(){
-
- var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('newlist')/items";
- alert(requestUri);
- $.ajax({
- url: requestUri,
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose"
-
- },
-
- success: onSuccess,
-
- error: onError
-
- });
-
- function onSuccess(data) {
- $.each(data.d.results,function(index,val){
-
- alert(val.Title);
-
- });
-
- }
-
- function onError(error) {
-
-
- }
-
- });
-
- });
-
- </script>
-
- <input type="button" id="btnClick" value="Click to Create List Item"/>
Thanks for reading my blog.