I am easily able to create record in other lists using rest API.
But with this one list, api failed. Listname: Project_List Can anyone please help me.
Thanks
Code:
function GetItemTypeForListName(name){ return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem"; } function AddListItem(){ var listName = "Project_List"; var itemType = GetItemTypeForListName(listName); var myID =""; var name = "276 Flinders St"; var item = { "__metadata": { "type": itemType }, "Title": name }; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + myID + ")", type: "POST", contentType: "application/json;odata=verbose", data: JSON.stringify(item), headers: { "Accept": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "IF-MATCH": "*", "X-HTTP-Method":"POST", }, success: function (data) { alert("success"); }, error: function (data) { alert("failed"); } }); }
Edit 1: I tried with all solution which you guys gave, but still not working
Edit 2:
error: function (error) { console.log(error); }
and add the error message you got in console. Also, try the suggestions given below in my answer and let me know if it works for you.