0

My Code:

<script>
    $('#submitdata').click(function(){

    var itemProperties = {
        '__metadata': { "type": "SP.List" },
        "Title": FirstName  

    };

    $.ajax({
         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ChangeOfAddressList')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(itemProperties),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            console.log(JSON.stringify(data.d));
        },
        error: function (data) {
            console.log(data.responseText);
        }
    });
});
</script> 

I get "FirstName is not defined" in chrome debugger. Everything else seems to work as it does actually reach the list it just can't populate it with anything meaningful This is all triggered by a submit. The id of the input is "name"

2
  • Because you are treating FirstName as a function, do you mean "FirstName"? – Eric Alexander May 4 '16 at 16:13
  • Yep, You are right, however, instead of inputting the <input type="text" id="FirstName"/> it just put in the text "FirstName". Just need to figure that out and Illl go home – Stacker May 4 '16 at 16:21
0

Based on your comment response, you'd do it like:

var itemProperties = {
    '__metadata': { "type": "SP.List" },
    "Title": $("#FirstName").val();

};
1
  • Cheers, It worked except I just had to remove the ; at the end. – Stacker May 4 '16 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.