Reputation: 1519
so I have been testing a bunch of new different JS code to see if I can get the POST request to send information to a SharePoint list. When I run my newest block, it tells me "Error: Line 20: Unexpected token" when I call $.ajax
saying the period is what is unexpected? I truly don't understand.
Here is my JS code:
$(document).ready(function(){
$("#btnSubmit").click(function(){
saveDelivDetails();
});
});
function saveDelivDetails(){
var itemType = GetListItemTpye(listname);
var item = {
"__metadata":{"type":itemType},
"Program":$("#dProgram").val(),
"Deliverable":$("#dDeliverable").val(),
"To":$("#dTo").val(),
"Date":$("#dDate").val(),
"Approved":$("#dApproved").val(),
"Notes":$("#dNotes").val()
};
var requestUrl = _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('"+listname+"')/items",
$.ajax({
url: requestUrl,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers:{
"Accept":"application/json;odata=verbose",
"X-RequestDigest":$("#__REQUESTDIGEST").val()
},
success: onSuccess,
error: onError,
});
function onSuccess(data){
alert("New Item Created");
$("#txtSubmitName").val();
}
function onError(error){
alert('error' + error);
console.log(error);
}
function GetListItemType(name){
return "SP.Data."+CharacterData(0).toUpperCase().name.slice(1)+"ListItem";
}
Upvotes: 1
Views: 120
Reputation: 1674
You have a ,
after line 19.
var requestUrl = _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('"+listname+"')/items",
Upvotes: 2