I need to create an HTML form with two text boxes and a button that you click the update button it inserts the two values in a sharepoint list. Below an example of what I'm trying to do:
// Function to save data in SharePoint list
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.TestListItem' }, 'Title': 'Test'},
headers: {
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
}
}();
I think the problem is in the ajax part but i dont know how fix. Any help?