Skip to content

Instantly share code, notes, and snippets.

@setunai
Created February 28, 2012 15: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 setunai/1933054 to your computer and use it in GitHub Desktop.
Save setunai/1933054 to your computer and use it in GitHub Desktop.
クロスドメインへのアクセスが回避できるXMLHttpRequest2
<html>
<head>
<title>XHR2/jquery test</title>
</head>
<body>
<input type="text" id="zip" style="width:100px;" value="2210824">
<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">
// http://blog.setunai.net/20120229/%e3%82%af%e3%83%ad%e3%82%b9%e3%83%89%e3%83%a1%e3%82%a4%e3%83%b3%e3%81%b8%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%8c%e5%9b%9e%e9%81%bf%e3%81%a7%e3%81%8d%e3%82%8bxmlhttprequest2/
(function ($) {
var api = 'http://api.aoikujira.com/zip/json/';
$('#run').click(function (){
var zip = $('#zip').val();
var url = api + zip;
$.getJSON(url).then(
function (json){
alert(json.address);
},
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