Last active
December 29, 2015 20:58
-
-
Save shoken0x/7726712 to your computer and use it in GitHub Desktop.
MongoDB Advent Calendar 2013 1日目
http://qiita.com/syokenz/items/00b06ac01adeeaebada4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<title>MongoDB Advent Calendar 2013</title> | |
<link rel="stylesheet" href="style.css"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> | |
<script type="text/javascript"> | |
<!-- | |
var find = function(option){ | |
$.ajax({ | |
url: 'http://localhost:28017/adventcalendar/appinfo/', | |
type:"get", | |
dataType: 'json', | |
success : function(data) { | |
if (option === "last") { | |
for (var i=0; i < data.rows.length; i++){ | |
if ( i == data.rows.length -1 ) { | |
$('#document').append('<li><p>' + data.rows[i].destination + '</p></li>'); | |
} | |
} | |
} else { | |
for (var i=0; i < data.rows.length; i++){ | |
if ( typeof data.rows[i].destination !== "undefined" ) { | |
$('#document').append('<li><p>' + data.rows[i].destination + '</p></li>'); | |
} | |
} | |
} | |
}, | |
error : function(){ | |
alert('error'); | |
} | |
}); | |
}; | |
find("all"); | |
//insert | |
$(function(){ | |
$('#post').click(function(){ | |
$.ajax({ | |
type:"post", | |
url:"http://localhost:28017/adventcalendar/appinfo/", | |
data: JSON.stringify({"destination": $("#destination").val()}), | |
datatype : 'json', | |
success : function(data) { | |
console.log('post success'); | |
console.log(data); | |
find("last"); | |
}, | |
error : function(){ | |
console.log('error'); | |
} | |
}); | |
}); | |
}); | |
// --> | |
</script> | |
</head> | |
<body> | |
<header> | |
<h1>MongoDB Advent Calendar 2013</h1> | |
</header> | |
旅行した場所を登録してね : <input type="text" id="destination" > | |
<button id="post">post</button> | |
<ul> | |
<div id="document"></div> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
style.css