I'm working on a form that writes to a SharePoint list when submitting as a new entry in the list. I've got the AJAX code in place and it seems to connect out to the list okay, however I'm receiving the following error when attempting to create the entry:
SCRIPT5009: 'data' is not defined
Here's my code, the data is pulled from the text boxes in the form, I'm just not certain whether they've been added to the JSON array properly.
function AddListItem() {
var ref = $("#ref").val();
var userID = $("#userID").val();
var impact = $("#impact").val();
$.ajax
({
url: "https://office4.bt.com/sites/ccim/Portal/_api/web/lists/GetByTitle('ImpactFeedback')/items",
type: "POST",
data: JSON.stringify
({
__metadata:
{
type: "SP.Data.TestListItem"
},
Title: ref,
UIN: userID,
Issue: impact,
Email: email,
}),
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "POST"
},
success: function(data, status, xhr)
{
retriveListItem();
},
error: function(xhr, status, error)
{
$("#ResultDiv").empty().text(data.responseJSON.error);
}
});
}
In your error callback, change:
$("#ResultDiv").empty().text(data.responseJSON.error);
to
$("#ResultDiv").empty().text(xhr.responseJSON.error);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.