0

Here are the columns I have in the backend list.enter image description here Here's how I am sending the data to the backend list through a POST request using AJAX.

var item = {
    __metadata: { type: "SP.Data.ListNameListItem" },
    Column1: { '__metadata': {' type': 'Collection(Edm.String)' }, 'results':  ['data1'] },
    Column2: { '__metadata': {' type': 'Collection(Edm.String)' }, 'results':  ['data2'] }
}

For Column1, how do I select 1st radio button and select a value inside it and for Column2, how do I select 2nd radio button and send a text of my own into it?

0

The following example code for your reference.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function createListItem() {
    var listTitle="CL1224";
    var item = {
        "__metadata": { "type": "SP.Data."+listTitle+"ListItem" },
        "Title":"MyTest",
        "Column1":"data1",
        "Column2":"data5"
    };

    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            alert('Success');
            //window.location.href=window.location.href;
        },
        error: function (err) {
            alert(JSON.stringify(err));
        }
    });
}
</script>
<button type="button" onclick="createListItem()">Submit</button>

enter image description here

1
  • Oops, I didn't try the default method of sending just the data. This is working, thank you!
    – psvs
    Jan 1 '20 at 14:27

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.