发布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() };
- 如何显示人类可读的“时间前”
- CKEditor,初始化使用insertElement添加的小部件
- 如何使用JQuery更改onClick复选框的值?
- IE 8中关于flash对象的jQuery.prepend()的“无效参数”
- 在.trigger中使用时,冒号在jQuery中意味着什么?
- 使用.bind()避免使用.call()和.apply()
- 我可以替换或修改jQuery UI小部件上的函数吗? 怎么样? (猴子补丁)
- 删除字符串中的所有HTML标签(使用jquery text()函数)
- 用于构建类似桌面的Web应用程序的Javascript库:ExtJS,jQuery,YahooUI,Mocha,SproutCore,Cappuccino,其他?