Skip to main content
added 768 characters in body
Source Link
Ganesh Sanap - MVP
  • 47.3k
  • 22
  • 32
  • 64

The REST API endpoint /items(<itemId>) returns the list item data in data.d and not in data.d.results.

So, try changing your success function like this:

success: function (data) {
    console.log(data.d);
}

Here's working example where I am fetching Title of list item and showing it in label on DOM:

<p> Title:
    <label id="lblActions"></label>
</p>

<script type="text/javascript">
    $(document).ready(function() {
        getListItem(_spPageContextInfo.webAbsoluteUrl, 1);
    });

    function getListItem(url, itemId) {
        $.ajax({
            url: url + "/_api/web/lists/getbytitle('TestList')/items(" + itemId + ")?$select=Title",
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                if(data.d) {
                    $("#lblActions").text(data.d.Title);
                } else {
                    $("#lblActions").text("Item not found!");
                }
            },
            error: function (error) {
                console.log(error);
            }
        });
    }
</script>

Output:

enter image description here

The REST API endpoint /items(<itemId>) returns the list item data in data.d and not in data.d.results.

So, try changing your success function like this:

success: function (data) {
    console.log(data.d);
}

The REST API endpoint /items(<itemId>) returns the list item data in data.d and not in data.d.results.

So, try changing your success function like this:

success: function (data) {
    console.log(data.d);
}

Here's working example where I am fetching Title of list item and showing it in label on DOM:

<p> Title:
    <label id="lblActions"></label>
</p>

<script type="text/javascript">
    $(document).ready(function() {
        getListItem(_spPageContextInfo.webAbsoluteUrl, 1);
    });

    function getListItem(url, itemId) {
        $.ajax({
            url: url + "/_api/web/lists/getbytitle('TestList')/items(" + itemId + ")?$select=Title",
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                if(data.d) {
                    $("#lblActions").text(data.d.Title);
                } else {
                    $("#lblActions").text("Item not found!");
                }
            },
            error: function (error) {
                console.log(error);
            }
        });
    }
</script>

Output:

enter image description here

Source Link
Ganesh Sanap - MVP
  • 47.3k
  • 22
  • 32
  • 64

The REST API endpoint /items(<itemId>) returns the list item data in data.d and not in data.d.results.

So, try changing your success function like this:

success: function (data) {
    console.log(data.d);
}