i checked it in console it works successfully.And the problem is that i didn't show any changes in TestList in SP environment.
$(document).ready(function () { createListItemWithDetails('TestList', 'http://sp20139:85', 'TestListRest', function (data) { console.log('New task ' + data.d + ' has been created'); }, function (data) { console.log(JSON.stringify(data.d)); }); }); function createListItemWithDetails(listName, siteUrl, title, success, failure) { var itemType = GetItemTypeForListName(listName); var item = { "__metadata": { "type": itemType }, "Title": title }; $.ajax({ url: siteUrl + "/_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) { console.log(data); success(data); }, error: function (data) { failure(data); } }); } function GetItemTypeForListName(name) { return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem"; }i checked it in console it works successfully.And the problem is that i didn't show any changes in TestList in SP environment.