<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script type="text/javascript"> var listName="CL0206"; function AddListItem(){ var itemType = GetItemTypeForListName(listName); var serverDetails='{"Server Name": "Production","Domain": "Gmail","Environment":"UAT"}'; var item = { "__metadata": { "type": itemType }, "Title": "testing", "ServerDetails":serverDetails }; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/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'); }, error: function (data) { alert(JSON.stringify(error)); } }); } // Get List Item Type metadata function GetItemTypeForListName(name) { return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem"; } </script> <input type="button" onclick="AddListItem()" value="AddListItem"/>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter