我不知道您的问题是否已解决,但以下是共享点托管应用程序对共享点列表进行跨域调用的列表示例中的添加、删除和更新项目。
function addItem() {
var executor = new SP.RequestExecutor(appweburl);
var dataTobeSent = {
__metadata: { "type": "SP.Data.TestListforAppListItem" },
Title: $("#col1").val(),
testCol1: $("#col2").val(),
test_x0020_col_x0020_2: $("#col3").val()
};
var sendData = JSON.stringify(dataTobeSent);
executor.executeAsync(
{
url:
appweburl +
"/_api/SP.AppContextSite(@target)/web/lists/getByTitle('testListforApp')/items?@target='" +
hostweburl + "'",
contentType: "application/json;odata=verbose",
method: "POST",
body: sendData,
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: getAllListItems,
error: errorHandler
}
);
}
function deleteItem(id) {
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync(
{
url:
appweburl +
"/_api/SP.AppContextSite(@target)/web/lists/getByTitle('testListforApp')/items(" + id + ")?@target='" +
hostweburl + "'",
contentType: "application/json;odata=verbose",
method: "POST",
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-Http-Method": "DELETE",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": "*"
},
success: getAllListItems,
error: errorHandler
}
);
}
function updateItem(id) {
var executor = new SP.RequestExecutor(appweburl);
var dataTobeSent = {
__metadata: { "type": "SP.Data.TestListforAppListItem" },
Title: $("#col1").val(),
testCol1: $("#col2").val(),
test_x0020_col_x0020_2: $("#col3").val()
};
var sendData = JSON.stringify(dataTobeSent);
executor.executeAsync(
{
url:
appweburl +
"/_api/SP.AppContextSite(@target)/web/lists/getByTitle('testListforApp')/items(" + id + ")?@target='" +
hostweburl + "'",
contentType: "application/json;odata=verbose",
method: "POST",
body: sendData,
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-HTTP-Method": "MERGE",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": "*"
},
success: getAllListItems,
error: errorHandler
}
);
}
希望这可以帮助。