Skip to content

Instantly share code, notes, and snippets.

@setunai
Created February 26, 2012 03:20
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 setunai/1912532 to your computer and use it in GitHub Desktop.
Save setunai/1912532 to your computer and use it in GitHub Desktop.
jQueryでクロスドメインのjson取得(JSONP)
<html>
<head>
<title>jsonp/jquery test</title>
</head>
<body>
<input type="text" id="url" style="width:300px;" value="http://blog.setunai.net/">
<input type="button" id="run" value="test">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
(function ($) {
var api = 'http://api.b.st-hatena.com/entry.count?callback=?';
$('#run').click(function (){
var url = $('#url').val();
$.getJSON(api, {'url': url}).then(
function (cnt){
alert(cnt);
},
function (){
alert('error dayo');
}
);
});
})(jQuery);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment