如何使用Rest将数据放在sharepoint列表中

时间:2014-01-07 17:31:47

标签: javascript rest sharepoint-2013

我可以使用GET方法发出请求并使用数据,但现在我需要在SharePoint中创建一个html表单并使用javascript提交到SharePoint列表。有什么帮助吗?

    PostFormBuilder.RESTPost = function (listTitle, query) {
    var execute = function (listTitle, query) {
        var restUrl = _spPageContextInfo.webServerRelativeUrl +
            "/_api/web/lists/getByTitle('" + listTitle + "')/items";
        if (query != "") {
            restUrl = restUrl + "?" + query;
        }
        var deferred = $.ajax({
            url: restUrl,
            method: "POST",
            body: { '__metadata': { 'type': 'SP.Data.Modelo' }, 'Title': 'Test'},
            headers: {
                Authorization: "Bearer " + accessToken,
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json;odata=verbose",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
                "IF-MATCH": "*",
                "X-Http-Method": "MERGE"
            }
        });

        return deferred.promise()
    };

    return {
        execute: execute
    }
}();

0 个答案:

没有答案