-
-
Save kjunine/5493205 to your computer and use it in GitHub Desktop.
JSONP sample of Daum Search API using jQuery
This file contains hidden or 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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$.getJSON()
메소드를 이용할 때는 URL에?CALLBACK_NAME=?
부분을 붙여서 콜백 이름을 지정한다.