Skip to content

Instantly share code, notes, and snippets.

@kjunine
Forked from anonymous/jsonp.html
Last active December 16, 2015 20:29
Show Gist options
  • Save kjunine/5493205 to your computer and use it in GitHub Desktop.
Save kjunine/5493205 to your computer and use it in GitHub Desktop.
JSONP sample of Daum Search API using jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSONP</title>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
var apikey = 'DAUM_SEARCH_DEMO_APIKEY';
function callWithAjax(q) {
$.ajax({
type: 'get',
url: 'http://apis.daum.net/search/blog',
data: {
apikey: apikey,
q: q,
output: 'json'
},
dataType: 'jsonp',
jsonp: 'callback',
success: function(json, status, xhr) {
console.log(json);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function callWithGetJSON(q) {
var url = 'http://apis.daum.net/search/blog?callback=?';
$.getJSON(url, {
apikey: apikey,
q: q,
output: 'json'
}, function(json, status, xhr) {
console.log(json);
});
}
callWithAjax('다음');
callWithGetJSON('네이버');
});
</script>
</body>
</html>
@kjunine
Copy link
Author

kjunine commented May 1, 2013

$.getJSON() 메소드를 이용할 때는 URL에 ?CALLBACK_NAME=? 부분을 붙여서 콜백 이름을 지정한다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment