6

I have to access the sharepoint 2013 list from the site under another web application in the same farm. Is it possible I tried it but, it is not happening. Both the web applications lie in the same sharepoint 2013 central administration. I tried it by using rest api, also by using javascript,

Following is my code,

<script type="text/javascript">

jQuery.noConflict();

var issueTracklist;

function getItems()
{

    var clientcontext = new SP.ClientContext("http://mypod.pa.bitwiseglobal.com/issuetracker");
    issueTracklist = clientcontext.get_web().get_lists().getByTitle('TicketTracker');   
    var projectcamlQuery = new SP.CamlQuery();      
    projectcamlQuery.set_viewXml("<View><Query><FieldRef Name='ID' /></Query></View>");
    this.issuecollListItem = issueTracklist.getItems(projectcamlQuery); 
    clientcontext.load(issuecollListItem);  
    clientcontext.executeQueryAsync(Function.createDelegate(this, this.onIssueTrackSucceeded), Function.createDelegate(this, this.onIssueTrackFailed));

}

function onIssueTrackSucceeded(sender,args)
{
    alert(issuecollListItem.get_itemCount());
}

function onIssueTrackFailed(sender,args)
{
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

</script>
  • You want using JSOM or CSOM? CSOM is definitely possible as it will run server side and you can create client context with Url. However, it is not possible in JSOM from what I have tried. Web Services should be possible. – Prakash - Crow Canyon Dec 16 '15 at 6:55
  • Yes I need to do it using javascript, which web services we need to use? – Niranjan Kulkarni Dec 16 '15 at 6:56
  • Can we do it using SPServices. – Niranjan Kulkarni Dec 16 '15 at 7:11
  • 1
    You'll get the Cross-domain policy which can be solved by using the SP.RequestExecutor. See more on MSDN msdn.microsoft.com/en-us/library/office/fp179927.aspx – must19 Jan 4 '16 at 16:51
2

If you use JavaScript code loaded from Web app A, cross-domain Policy will prevent you from accessing data hosted in Web app B (different domain). One option would be to host/load your script file from Web app B (i.e. linking from page in Web app A to a script file residing in Web app B).

  • OK I will give it a try. Do you have some link regarding that. – Niranjan Kulkarni Jan 5 '16 at 7:05
  • Do you mean that I need to create the javascript file in Web app B gather the data in it. And then just give the referenc of the JS file in Web app A and access the data from that file. – Niranjan Kulkarni Jan 5 '16 at 8:03
  • Yes, this is what I mean! :) Script file loaded from Web app B (i.e. domain B) should be allowed to access data (Ajax calls) to Web app B. – Evariste Jan 5 '16 at 8:06
  • No its not happening it is not accessing that list data and is giving some request failed error. – Niranjan Kulkarni Jan 5 '16 at 10:56
0

Actually it is not possible, as it is a cross domain request the two pages fall in different security zones and hence proxy page that is required is not loaded in sharepoint. This has been done for security purposes by the browsers. The cookies fall in different security zones of the browsers of respective pages, and when the zones don't match the data cannot be accessed. It is possible only in the SharePoint addin's (apps) since there exists the apphost page that consists of the IFrame which has the same security zone as that of the calling page. It may be possible in Internet Explorer by adding the *.microsoftonline.com & respective two url's of web applications to the same secutrity zone. So the solution would be to create WCF. Or a timerjob or utility that may create the same list in your web application as parallel to that list that you want to access.

For more information please have look at,

https://msdn.microsoft.com/library/jj612823%28v=office.15%29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.