Sharepoint 2013 更新空字段以包含值-rest API
因此,我有一段代码,如果字段有内容,它将更新字段值,尽管如果我尝试更新的字段为null,则该值不会更新。我做错什么了吗Sharepoint 2013 更新空字段以包含值-rest API,sharepoint-2013,sharepoint-rest-api,Sharepoint 2013,Sharepoint Rest Api,因此,我有一段代码,如果字段有内容,它将更新字段值,尽管如果我尝试更新的字段为null,则该值不会更新。我做错什么了吗 siteURL = _spPageContextInfo.webAbsoluteUrl; var apiPath = _spPageContextInfo.webAbsoluteUrl +"/_api/lists/getbytitle('Training%20Copy')/items/getbyid(9)"; $.ajax(
siteURL = _spPageContextInfo.webAbsoluteUrl;
var apiPath = _spPageContextInfo.webAbsoluteUrl +"/_api/lists/getbytitle('Training%20Copy')/items/getbyid(9)";
$.ajax({
url: apiPath,
type: "POST",
headers: {
Accept: "application/json;odata=verbose"
},
data: JSON.stringify
({
__metadata:
{
type: "SP.Data.Training_x0020_CopyItem"
},
Admin_x0020_Function: "Have content"
}),
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
async: false, success: function(data) {
console.log("Item updated successfully");
}, eror: function(data) {
console.log("An error occurred. Please try again.");
}
})
ajax请求中有两个Header参数,不清楚是否会影响 我的测试代码供您参考:
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
Update()
function Update(){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Doc')/items(9)",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
data: JSON.stringify({__metadata:{'type':'SP.Data.DocItem'},test:'test'}),
/*where Title is column name and add your desired new data*/
success: function(data) {
console.log(data);
},
error: function(error) {
alert(JSON.stringify(error));
}
});
}
})
</script>
$(文档).ready(函数(){
更新()
函数更新(){
$.ajax({
url:_spPageContextInfo.webAbsoluteUrl+“/_api/web/lists/GetByTitle('Doc')/items(9)”,
类型:“POST”,
标题:{
“接受”:“application/json;odata=verbose”,
“X-RequestDigest”:$(“#u-RequestDigest”).val(),
“内容类型”:“应用程序/json;odata=verbose”,
“如果匹配”:“*”,
“X-HTTP-Method”:“合并”
},
数据:JSON.stringify({uu元数据:{'type':'SP.data.DocItem'},test:'test'}),
/*其中Title是列名并添加所需的新数据*/
成功:函数(数据){
控制台日志(数据);
},
错误:函数(错误){
警报(JSON.stringify(错误));
}
});
}
})