Last active
December 20, 2015 13:19
-
-
Save tinybeans/6138355 to your computer and use it in GitHub Desktop.
MTDDC 2013 サンプル - jQuery.ajax() を使って Data API からデータを取得して表示
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> | |
<head> | |
<meta charset="UTF-8"> | |
<title>MTDDC</title> | |
<style type="text/css"> | |
#result-container { | |
position: relative; | |
} | |
#result-img { | |
display: block; | |
position: absolute; | |
margin: 50px; | |
} | |
#result { | |
display: none; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="result-container"> | |
<div id="result"></div> | |
<img id="result-img" src="/images/indicator.gif" alt=""> | |
</div> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="mustache.js"></script> | |
<script type="text/javascript"> | |
(function($){ | |
var jsonPath = "http://your-host/mt/mt-data-api.cgi/v1/sites/2/entries?search=mtappjquery&fields=title,permalink"; | |
$.ajax({ | |
type: "GET", | |
cache: true, | |
dataType: "json", | |
url: jsonPath, | |
success: function(json){ | |
var _html = [ | |
'<ul>', | |
'{{#items}}', | |
'<li><a href="{{permalink}}">{{title}}</a></li>', | |
'{{/items}}', | |
'</ul>' | |
]; | |
_html = Mustache.render(_html.join(""), json); | |
$("#result-img").fadeOut(function(){ | |
$("#result").html(_html).fadeIn("slow"); | |
}); | |
} | |
}); | |
})(jQuery); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment