Security Validation Error when trying to create list item across site collections using Javascipt SP2010

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/287673

Question

I'm trying to create a list item across another site collection using JavaScript. When trying to call the following function I receive this error.

"request failed. the security validation for this page is invalid. click back in your browser"

function CPECalendar(ApprovalInfo) {
var siteUrl = '/sites/npeeng';
var context = new SP.ClientContext(siteUrl);
var context = SP.ClientContext.get_current();
var oList = context.get_web().get_lists().getByTitle("Activations");
var item = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(item);
oListItem.set_item("Location", "TESTING, PLEASE DISREGARD");
oListItem.update();
context.load(oListItem);
context.executeQueryAsync(silentSuccess, failure);

}

I've read in numerous places about AllowingUnsafeUpdates, but not sure if that pertains to this exact problem or works with js. Is there a viable solution I can use with JavaScript? Thanks.

Was it helpful?

Solution

We cannot make cross-sitecollection calls from JSOM in SharePoint 2010.

Here is a similar issue for your reference: https://social.technet.microsoft.com/Forums/en-US/a1853212-62ac-4a15-a47f-e27bc1c35187/hot-to-get-list-which-is-located-in-different-site-collection-using-ecmascript?forum=sharepointgeneralprevious

The scope of client object model is site collection, you cannot access to the content out of the current site collection.

Additionally, making a call from one SharePoint site to another is not allowed because both of these scenarios would result in cross-site scripting.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top