Hi,
I am trying to create list item in SharePoint Hosted app using REST api. Below is my code in App.js:
function createItem() {var listUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('List1')/items";
//alert(listUrl);
requestDetails = {
"__metadata": { "type": "SP.Data.List1ListItem" },
"Title" : "NoTitle",
};
actualData = JSON.stringify(requestDetails);
requestHeaders = {
"accept": "application/json;odata=verbose",
"contentType": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
};
$.ajax({
url: listUrl,
method: "POST",
headers: requestHeaders,
data: actualData,
success: createdsuccessfully(),
error: alert("creation failed")
});
}
function listLink() {
var link = document.getElementById("listLink");
var clickurl = spAppWebUrl + "/lists/List1/AllItems.aspx";
link.setAttribute("href", clickurl);
}
function createdsuccessfully() {
alert("Item created");
}
The target list(List1) is in appweb and app permission is set to web(scope) write permission. This is never creating list item and calling both success and error method of $.ajax.
I am not sure what is wrong here. List contains only one column i.e. Title and I am trying to create new Title value i.e. NoTitle.
Please help.