Home > Web Front-end > JS Tutorial > Code to get what happened on this day in history_Basic knowledge

Code to get what happened on this day in history_Basic knowledge

WBOY
Release: 2016-05-16 16:52:35
Original
1900 people have browsed it

Today’s json interface in history, share it with everyone, the data comes from wiki

Copy code The code is as follows:

//http://history.sturgeon.mopaas. com //Homepage
//http://history.sturgeon.mopaas.com/jsonp?callback=? //jsonp interface
//http://history.sturgeon.mopaas.com/jsonp // json interface
//http://history.sturgeon.mopaas.com/jsonp/1@1 //January 1st in history
//http://history.sturgeon.mopaas.com/ 1@1 //January 1st in history

$.getJSON('http://history.sturgeon.mopaas.com/jsonp?callback=?',function(data){
parserTodayObj(data);
});
function parserTodayObj(todayObj){
for(var key in todayObj){
if(/^.*birth.*$/.test(key)){
doBirthday(todayObj[key]);
}
if(/^.*Holiday.*$/.test(key)){
doHoliday(todayObj[key]);
}
if(/^.*Customs.* $/.test(key)){
doHoliday(todayObj[key]);
}
if(/^.*Death.*$/.test(key)){
doDeath( todayObj[key]);
}
if(/^.*事记.*$/.test(key)){
doMemorabilia(todayObj[key]);
}
}
}

parserTodayObj(todayObj);

function doBirthday(birthdays){
if(birthdays.length != 0){

$(document.body).append("

birth

");
for (var i = 0; i < birthdays.length; i ) {
var birthdayitem = birthdays[i];
$(document.body).append("

" birthdayitem "

");
};
}
}

function doHoliday(holidays){
if(holidays.length != 0){

$(document.body).append("

Holidays

");
for (var i = 0; i < holidays.length; i ) {
var item = holidays[i];
$(document.body).append("

" item "

");
};
}
}

function doDeath(deaths){
if(deaths.length != 0){

$(document.body).append("

Death

");
for (var i = 0; i < deaths.length; i ) {
var item = deaths[i];
$(document.body).append("

" item "

");
};
}
}

function doMemorabilia(memorabilias){
if(memorabilias.length != 0){

$(document.body).append("

Major Events

");
for (var i = 0; i < memorabilias.length; i ) {
var item = memorabilias[i];
$(document.body).append("

" item "

");
};
}
}

Copy code The code is as follows:

//http://history.sturgeon.mopaas.com //Homepage
//http://history.sturgeon.mopaas.com/jsonp?callback=? //jsonp interface
//http://history.sturgeon.mopaas.com/jsonp //json interface
//http://history.sturgeon.mopaas.com/jsonp/1@1 //January 1 in history Day
//http://history.sturgeon.mopaas.com/1@1 //January 1st in history

$.getJSON('http://history.sturgeon.mopaas.com/jsonp?callback=?',function(data){
parserTodayObj(data);
});
function parserTodayObj(todayObj){
for(var key in todayObj){
if(/^.*birth.*$/.test(key)){
doBirthday(todayObj[key]);
}
if(/^.*Holiday.*$/.test(key)){
doHoliday(todayObj[key]);
}
if(/^.*Customs.* $/.test(key)){
doHoliday(todayObj[key]);
}
if(/^.*Death.*$/.test(key)){
doDeath( todayObj[key]);
}
if(/^.*事记.*$/.test(key)){
doMemorabilia(todayObj[key]);
}
}
}

parserTodayObj(todayObj);

function doBirthday(birthdays){
if(birthdays.length != 0){

$(document.body).append("

birth

");
for (var i = 0; i < birthdays.length; i ) {
var birthdayitem = birthdays[i];
$(document.body).append("

" birthdayitem "

");
};
}
}

function doHoliday(holidays){
if(holidays.length != 0){

$(document.body).append("

Holidays

");
for (var i = 0; i < holidays.length; i ) {
var item = holidays[i];
$(document.body).append("

" item "

");
};
}
}

function doDeath(deaths){
if(deaths.length != 0){

$(document.body).append("

Death

");
for (var i = 0; i < deaths.length; i ) {
var item = deaths[i];
$(document.body).append("

" item "

");
};
}
}

function doMemorabilia(memorabilias){
if(memorabilias.length != 0){

$(document.body).append("

Major Events

");
for (var i = 0; i < memorabilias.length; i ) {
var item = memorabilias[i];
$(document.body).append("

" item "

");
};
}
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template