Skip to content

Instantly share code, notes, and snippets.

@shoken0x
Last active December 29, 2015 20:58
Show Gist options
  • Save shoken0x/7726712 to your computer and use it in GitHub Desktop.
Save shoken0x/7726712 to your computer and use it in GitHub Desktop.
MongoDB Advent Calendar 2013 1日目 http://qiita.com/syokenz/items/00b06ac01adeeaebada4
<!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>
@shoken0x
Copy link
Author

shoken0x commented Dec 1, 2013

style.css

body {
  margin: 0;
  padding: 0;
}

h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd {
  margin: 0;
  padding: 0;
}

header {
  background: #333;
  color: #FFF;
}

header h1 {
  font-size: 28px;
  padding: 10px;
  text-align: center;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment