$(document).ready(function () {
getUserName();
AddData("title from JS", "CRJ");
function AddData(newItemTitle, school_locationn) {
var listName = "School Name";
CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, newItemTitle, school_locationn, function () {
console.log("New Item has been created successfully.");
}, function () {
console.log("Ooops, an error occured. Please try again.");
});
}
// CREATE Operation
// listName: The name of the list you want to get items from
// weburl: The url of the web that the list is in.
// newItemTitle: New Item title.
// success: The function to execute if the call is sucesfull
// failure: The function to execute if the call fails
function CreateListItemWithDetails(listName, webUrl, newItemTitle, school_locationn, success, failure) {
var itemType = GetItemTypeForListName(listName);
var item = {
"__metadata": { "type": itemType },
"Title": newItemTitle,
"School Location": school_locationn
};
$.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) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
// Get List Item Type metadata
function GetItemTypeForListName(name) {
return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
var fun1 = function () {
}
});
Sharepoint Site COllection URL - http://xxxxxxxxx.win-xxxxx:47699/
After pressing F5 (Visual studion ) getting error in browser >
List 'School Name' does not exist at site with URL 'http://app-xxxxxxxxx.win-xxxxx:47699/SharePointAddIn1'.
I think the error is due to app url is different from site collection url , but my question is if so , how to fix it ? As my app will be in different url .
Please help . Thank you .