0

Scenario: I have one Site Collection in abc.com domain and other Site Collection I have inside xyz.com domain. Now I want to access list item from abc.com domain inside xyz.com domain. Both Sites are created in Office 365. I tried with JSOM and REST api but it fails while making call.

Please advice with code sample.

Thanks!

2
  • Call to another domain not working, try JQuery JSONP stackoverflow.com/questions/7409155/… Commented Dec 13, 2018 at 12:46
  • I already tried with JSONP but it didn't work for me. And how we would authenticate users through code from other domain. Pls share code sample if any...Thanks Commented Dec 13, 2018 at 13:16

1 Answer 1

1

Make sure the two site collection in a same tenant and use have permission to get list data from another site collection.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    var siteCollUrl="https://xxx.sharepoint.com/sites/lz";
    var listName="CustomList";
    $.ajax({
        url: siteCollUrl + "/_api/web/lists/getbytitle('"+listName+"')/items",
        type: "GET",
        headers: {
            "Accept": "application/json;odata=verbose",
        },
        success: function (data) {
            var titles="";
            $.each(data.d.results,function(i,item){
                titles+="Title:"+item.Title+"\n";
            });
            alert(titles);
        },
        error: function (data) {
            alert(JSON.stringify(data));
        }
    });
})
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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