更新时间:2023-09-28 23:06:28
你好qasimidl,
Hi qasimidl,
请检查响应对象,你可以使用控制台。 log(响应)检查所有属性,并且应该包含新添加的Item Id(S.no)。
Please check the response object, you could use console.log(response) to check all the properties, and the new added Item Id (S.no) should be included.
不确定Web API中的详细逻辑,但我测试了Rest API插入项,在响应中返回项ID,如下所示:
Not sure about detailed logic in your Web API, but I tested with Rest API insert item, the item Id is returned in the response like this:
<script type="text/javascript">
var item = {
"__metadata": { "type": 'SP.Data.MyList3ListItem'},
"Title": "value change111"
};
.ajax({
url:_spPageContextInfo.webAbsoluteUrl +" / _ api / web / lists / GetByTitle('MyList3') / items",
类型:" POST",
header:{
" accept":" application / json; odata = verbose",
" X- RequestDigest":
.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('MyList3')/items", type: "POST", headers: { "accept": "application/json;odata=verbose", "X-RequestDigest":
(" #__ REQUESTDIGEST")。val(),
" content-Type":" application / json; odata = verbose"
},
数据:JSON.stringify(item),
/ *其中Title是列名,您可以通过拆分来添加更多列,* /
success:function(data){
console.log(data.d);
},
错误:函数(错误){
alert(JSON.stringify(error));
}
});
< / script>
("#__REQUESTDIGEST").val(), "content-Type": "application/json;odata=verbose" }, data: JSON.stringify(item), /*where Title is column name and you can add more columns by splitting with ,*/ success: function(data) { console.log(data.d); }, error: function(error) { alert(JSON.stringify(error)); } }); </script>
谢谢
***的问候