I am trying to access the list item using an APP in my office 365 share point hosted trial environment.It seems like the call REST call is failing, the alert in error function is getting executed.
This is the Url https://test.sharepoint.com/sites/AppSite/. I have created an APP called SharePointAppTest under AppSite web. There is a list called TestList created under Appsite web.TestList has an entry with ID as '1' and title as firstValue.
Below is the code I am using to access that item with ID using REST API
(function () {
$(document).ready(function () {
getListItem();
});
getListItem("https://test.sharepoint.com/sites/AppSite","TestList",1,"complete","failure");
})();
function getListItem(url, listname, id, complete, failure) {
$.ajax({
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
// Returning the results
alert("it is a success");
complete(data);
},
error: function (data) {
alert("it is a failure");
failure(data);
}
});
}