var request = new XMLHttpRequest();
request.open('GET', 'eventFeed.php', true);
console.log('request = ', request);
request.responseType = 'json';
request.send(null);
request.onload = function () {
var data = this.response.data;
for (var i = 0; i < data.length; i++) {
console.log(data[i].title + ' is a ' + data[i].start + '.');
}
if(!request.response.data) {
console.log('request.response.data is missing');
} else {
console.log('data = ', data, "\n",
new Calendar({
calContainer:'calBody',
newDate:'02/05/2009',
cEvents: data
}), Array.isArray(data));
}
}
<?
if(!empty($_GET['city'])) $_SESSION['city'] = $_GET['city'];
else {
// Выводим контент
}
?>
<script>
ymaps.ready(function(){
var geolocation = ymaps.geolocation;
$('#city').text('Город: '+geolocation.city);
$.ajax({
type: "GET",
url: "?city='" + YMaps.location.city,
data:{
city: YMaps.location.city,
},
});
});});
</script>
window.addEvent('domready',function(){
var request = new XMLHttpRequest();
request.open('GET', 'Demo - MooTools Events Calendar_files/data.json', true);
console.log('request = ', request);
request.responseType = 'json';
request.send(null);
request.onload = function () {
// begin accessing JSON data here
var data = this.response.data;
console.log('data = ', data);
for (var i = 0; i < data.length; i++) {
console.log(data[i].title + ' is a ' + data[i].start + '.');
}
console.log(new Calendar({
calContainer:'calBody',
newDate:'04/05/2018',
cEvents: data
}));
}
})
Затем, что может быть множественное применение. Если нет, тогда можно и без функции.