我正在使用以下变量通过JSON访问Songkick API ...
var url =
"//api.songkick.com/api/3.0/artists/12345/calendar.json?apikey=12345abc&jsoncallback=?";
$.getJSON(url, function (data) {
var events = data.resultsPage.results.event;
events.forEach(function (item, index, array) {
var event_month = moment(array[index].start.date).format("MMM");
var event_day = moment(array[index].start.date).format("D");
var event_date =
'<div class="event-list-item-date"><span class="month">' +
event_month +
'</span><span class="date">' +
event_day +
"</span></div>";
var event_venue = array[index].venue.displayName;
var event_city = array[index].location.city;
var event_link = array[index].uri;
var event_details =
'<div class="event-list-item-location">' +
event_city +
'<p><span class="event-list-item-venue">' +
event_venue +
'</span></p></div><div class="event-list-item-actions"><a href="' +
event_link +
'"class="btn" target="_blank"">TICKETS</a></div>';
if (event_month != "Invalid date" && event_day != "Invalid date") {
$(".event-list-item-wrapper").append(
'<div class="event-list-item">' +
event_date +
event_details +
"</div>"
);
}
});
});
这很好用,但是我需要使用下面的其他项(per_page = 10)访问相同的API,以访问网站上的另一个页面...
var url =
"//api.songkick.com/api/3.0/artists/12345/calendar.json?apikey=123abc**&per_page=10**&jsoncallback=?";
我不确定我如何使用完全相同的代码TWICE,但是对per_page进行了细微更改(没有将上述所有代码重复两次,只是为了更改一个per_page请求)。任何帮助表示赞赏。