[英]SharePoint 2013 App - CRUD operation
我不熟悉具有外部內容的Sharepoint 2013應用程序。 我可以從SQL中提取數據,並可以在“應用程序”頁面中填充。 但是我嘗試添加新數據,收到以下錯誤消息
來自網頁的訊息
{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\"}}}","status":400,"statusText":"Bad Request"}
我使用了以下代碼
create: function (dname, description) {
debugger;
$.ajax({
url: _spPageContextInfo.webServerRelativeUrl +
"/_api/web/lists/getByTitle('tblDomain_SP')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({'DomainName':dname,'Description':description}),
dataType: "json",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function () {
REST.DomainFormFiller.clear();
},
error: function (err) {
alert(JSON.stringify(err));
}
});
}
您能幫我將數據插入sql表嗎?
錯誤:
找到了沒有類型名稱的條目,但未指定預期的類型。 為了允許輸入沒有類型信息的信息,在指定模型時還必須指定期望的類型
由於缺少“列表項”條目中的“ Type
屬性而發生。
要創建列表項,您將需要包括列表項類型。 這是首次創建列表時由SharePoint自動創建的字符串。 有兩種方法可以做到這一點:
__metadata
屬性中找到該類型。 SP.Data.ListNameListItem
約定(例如,列表名是Test
,列表項類型是SP.Data.TestListItem
)。 然而,這並非總是如此。 例如,SharePoint自動將列表名稱的首字母大寫(例如,列表名稱test
列表項類型為SP.Data.TestListItem
)。 以下代碼段顯示了如何根據列表名稱生成列表項類型:
function GetItemTypeForListName(name) {
return"SP.Data." + name.charAt(0).toUpperCase() + name.slice(1) + "ListItem";
}
然后,您需要替換該行:
data: JSON.stringify({'DomainName':dname,'Description':description}),
與此:
data: JSON.stringify({'DomainName':dname,'Description':description,"__metadata": { "type": GetItemTypeForListName('tblDomain_SP') }}),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.