1

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";
}

1 Answer 1

2

You have a , after line 19.

var requestUrl = _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('"+listname+"')/items",
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I hate the small errors like this they drive me insane. Now it is telling me unexpected end of input aswell, but when I click on the console (</script></DIV>) thats what is throwing the error?
Nevermind I figured it out. I was missing the closing } from saveDelivDetails() function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.