Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Post函数错误:找到没有类型名称的条目_Jquery_Rest_Sharepoint_Sharepoint Online - Fatal编程技术网

Jquery Post函数错误:找到没有类型名称的条目

Jquery Post函数错误:找到没有类型名称的条目,jquery,rest,sharepoint,sharepoint-online,Jquery,Rest,Sharepoint,Sharepoint Online,我在尝试将数据发布到sharepoint列表时遇到ajax调用错误400 异常为Microsoft.SharePoint.Client.InvalidClientQueryException,消息为“找到了没有类型名称的条目,但未指定预期类型。若要允许没有类型信息的条目,则在指定模型时还必须指定预期类型。” 我的代码 //Get form digest value function getFormDigest(webUrl) { retur

我在尝试将数据发布到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()
};