I need to be able to make 2 ajax requests at the same time on one sharepoint page. One request comes from the current site, the other comes from a team site. If I use the different urls (/events) and (/travel) both will work on the page when used alone. There are only issues when I try to combine them (ie do the AJAX call for travel, in the succeed portion of the /events call). It works with both in edit mode, but if I save the page, it only shows items from /events, instead of also showing /travel.
$.ajax({
url: url, //THE ENDPOINT
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data) {
$.ajax({
url: urlB, //THE ENDPOINT
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(dataB) {
for (var iB = 0; iB < dataB.d.results.length; iB++) {
var dataStartB = dataB.d.results[iB].StartTime;
var dataEndB = dataB.d.results[iB].EndTime;
var isoStartB = new Date(parseInt(dataStartB.substring(6).slice(0,-2))).toISOString().replace("T"," ").split('.')[0];
var isoEndB = new Date(parseInt(dataEndB.substring(6).slice(0,-2))).toISOString().replace("T"," ").split('.')[0];
events.push({
id: dataB.d.results[iB].Id.toString(),
title: dataB.d.results[iB].Title,
start: isoStartB,
end: isoEndB,
url: ("../team/_vti_bin/listdata.svc/Grouptravel" + "(" + dataB.d.results[iB].Id + ")"),
allDay: dataB.d.results[iB].AllDayEvent.toString()
});
}
}
});
for (var i = 0; i < data.d.results.length; i++) {
var dataStart = data.d.results[i].StartTime;
var dataEnd = data.d.results[i].EndTime;
var isoStart = new Date(parseInt(dataStart.substring(6).slice(0,-2))).toISOString().replace("T"," ").split('.')[0];
var isoEnd = new Date(parseInt(dataEnd.substring(6).slice(0,-2))).toISOString().replace("T"," ").split('.')[0];
events.push({
id: data.d.results[i].Id.toString(),
title: data.d.results[i].Title,
start: isoStart,
end: isoEnd,
url: ("../_vti_bin/listdata.svc/Events/" + "(" + data.d.results[i].Id + ")"),
allDay: data.d.results[i].AllDayEvent.toString()
});
}