Codes For Getting Items from a SharePoint List using ID

Add some HTML Tags such as TextBox and Table Where the values will be binded after REST call.

Here is the snippet to perform the Above Action.

<input type=”text” id=’txt’ placeholder=”Enter the ID” >

<input type=”button” id=’btn’ value=”Click”>

 

<table id=”tab” border=1>
<tbody>
<tr id=”tr”>
</tr>
</tbody>
</table>
</div>

The jQuery reference File has to be added for reference.

/jquery-1.8.0.min.js

The function which Calls the GET method.

function RESTAPI(){

var x=$(‘#txt’).val();
var url = “/sites/_api/web/lists/GetByTitle(‘LISTNAME’)/items(” + x + “)?$format=JSON”;
$.ajax({
url: url1,
method: “GET”,

headers: {
“Accept”: “application/json;odata=verbose”,”Content-Type”: “application/json;odata=verbose”
},
success: function (data) {
console.log(data);

$(‘#val1’).text(data.d.Name + ” ” +data.d.Id)

},

error: function (error) {
console.log(JSON.stringify(error));
}
});
}
$(document).ready(function () {

$(“#btn”).click(function(){
RESTAPI();
});
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s