Skip to content

Instantly share code, notes, and snippets.

@tinybeans
Last active December 20, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinybeans/6138355 to your computer and use it in GitHub Desktop.
Save tinybeans/6138355 to your computer and use it in GitHub Desktop.
MTDDC 2013 サンプル - jQuery.ajax() を使って Data API からデータを取得して表示
<!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