Created
February 26, 2012 03:20
-
-
Save setunai/1912532 to your computer and use it in GitHub Desktop.
jQueryでクロスドメインのjson取得(JSONP)
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
<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