I am trying to retrieve list item data from different site collection in SP2013.
I am storing all site URL in an array and I am iterating this using for loop. while in for loop I have called another method which has REST code and I am passing site URL one by one to REST.
However this is not working as for loop keeps incrementing and REST is executing for only 1 site URL and giving me data from first site only. I think this is happening because of Async call.
SiteURL[] has 3 url and I want to get data from this 3 sites.
Code sample:
function getSubmissionNo(siteURL)
{
var currentNewUrl;
for(a=0;a<=siteURL.length;a++)
{
currentNewUrl=siteURL[a];
getDataUsingRest(currentNewUrl).done(function(result){})
}
}
function getDataUsingRest(requiredUrl)
{
var dfd=new $.Deferred;
$.ajax({
url: requiredUrl+"/_api/web/lists/getbytitle('E-files')/items?$select=ImgURL,FileRef&$expand=ContentType&$filter=ContentType eq 'Submission Folder'",
type: "GET",
asyn: false,
headers: {
"Accept": "application/json;odata=verbose",
},
success:function(data)
{
dfd.resolve();
dataReturned(data);
},
error:function(data)
{
dfd.reject();
}
});
return dfd.promise();
}
function dataReturned(data)
{
var k;
for(k=0;k< data.d.results.length;k++)
{
var item=data.d.results[k];
var subN = item.ImgURL;
var fileRefTest = item.FileRef;
console.log(fileRefTest);
}
}