How to retrieve SharePoint list item using list API using CSOM Ajax method ?

Posted on: 10/1/2016      No. of view(s): 106

How to retrieve SharePoint list item using list API using CSOM Ajax method ?


Here is the script to retrieve SharePoint list item using list API using CSOM Ajax method

<script>
$(document).ready(function(){

var ListName = "TestList"
var siteurl = _spPageContextInfo.webAbsoluteUrl;
var source = "filtervalue1"
var col = "filtercolumn1"

getEmployeeProfiles(ListName, siteurl , source, function(data,source){
                    var empname;
                         var items = data.d.results;            
                            if (items.length >0){
                                empname=items[0]["Emp_Name"];
                                $("#placeholder1").html(empname);
                            }
                     },function(data){
                                               
                     });

 });

function getEmployeeProfiles(listName, url, source, success, failure){

        var tempUrl = url+ "/_api/web/lists/getByTitle("+listName+")/items?$filter="+ col +" eq "+source+"";
        
        $.ajax({
            url: tempUrl,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                success(data,source);
            },
            error: function (data) {
                failure(data);
            }
        });
    }

</script>

<div id="placeholder1"></div>

Sponsors

Happy Reading.. Happy Programming :)