Friday, 21 July 2017

Sharepoint ListItems(Get,Delete)


Get Item From Sharepoint List

var siteURL=site url of user.
var Listname=sharepoint list name.

function GetItems(Success,Failure)
{
$.ajax(
{

url: siteURL+"/_api/web/lists/getbytitle('Listname')/items?",
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function (data) {
Success(data.d.results);
},
error: function (data) {
}    
});
}

function GetItemsSuccess(arrayvalues)
{
alert('Success');
}
function GetItemsFailure()
{
alert('failure');
}

Delete Item From Sharepoint List

var DocId=20;
function DeleteListitem()
{
$.ajax({
    url:siteUrl+ "/_api/web/lists/GetByTitle('Listname')/items('+DocId+')",
    type: "POST",
    headers: {
               "Accept": "application/json;odata=verbose",
               "content-type": "application/json; odata=verbose",
               "X-RequestDigest": $("#__REQUESTDIGEST").val(),
               "X-HTTP-Method": "DELETE",
               "If-Match": "*"
              } ,
    success: function(data)
        //alert("Item deleted successfully!");
      },
    error: function(err){
      //alert("Error while deleting item: " + JSON.stringify(err));
    }    
});
}

No comments:

Post a Comment

How to get the value from web.config(if any value assign as static Key)

Web.Config File:   <appSettings>     <add key="DomainName" value="PW" />     </appSettings> Cl...