发布function错误:找到没有类型名称的条目

尝试将数据发布到sharepoint列表时,我有一个ajax调用错误400。

例外是Microsoft.SharePoint.Client.InvalidClientQueryException并且消息是“找到了没有类型名称的条目,但没有指定预期类型。要允许没有类型信息的条目,还必须在指定模型时指定期望的类型。”

我的代码..

//Get form digest value function getFormDigest(webUrl) { return $.ajax({ url: webUrl + "/_api/contextinfo", method: "POST", headers: { "Accept": "application/json; odata=verbose" } }); } //Create list item to add to sharepoint list function createListItem(webUrl, listName, itemProperties) { return getFormDigest(webUrl).then(function (data) { return $.ajax({ url: webUrl + "/_api/web/lists/getbytitle('" + listName + "')/items", type: "POST", processData: false, data: JSON.stringify(itemProperties), headers: { "Accept": "application/json;odata=verbose", "X-RequestDigest": data.d.GetContextWebInformation.FormDigestValue, "Content-Type": "application/json;odata=verbose", "X-HTTP-Method": "POST" } }); }); } //Getting the item type of a list function GetItemTypeForListName(name) { return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem"; } //On button click $("#btn_post").click(function () { //Item properties var itemProperties = { _metadata: { "type": GetItemTypeForListName("EmployeeBirthdayWishes") }, Title: $("#title").val(), Wish: $("#birthday_wish").val(), FullNames: $("#fullNames").val() }; //Function call to create a list item createListItem(_spPageContextInfo.webAbsoluteUrl, "EmployeeBirthdayWishes", itemProperties) .done(function (data) { console.log(data); console.log("Task has been created successfully"); }).fail(function (error) { console.log(JSON.stringify(error)); alert(JSON.stringify(error)); }); }); 

尝试使用以下方法更改itemProperties对象:

 //Item properties var itemProperties = { "__metadata": { "type": GetItemTypeForListName("EmployeeBirthdayWishes") }, "Title": $("#title").val(), "Wish": $("#birthday_wish").val(), "FullNames": $("#fullNames").val() };