programing

jsonp with jquery

jooyons 2023. 4. 5. 21:33
반응형

jsonp with jquery

jsonp 요청을 jquery로 읽는 간단한 예를 들어주시겠습니까?작동이 안 돼요.

다음으로 작업 예를 제시하겠습니다.

<html><head><title>Twitter 2.0</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head><body>
<div id='tweet-list'></div>
<script type="text/javascript">
$(document).ready(function() {
    var url =  "http://api.twitter.com/1/statuses/user_timeline/codinghorror.json";
    $.getJSON(url + "?callback=?", null, function(tweets) {
        for(i in tweets) {
            tweet = tweets[i];
            $("#tweet-list").append(tweet.text + "<hr />");
        }
    });
});
</script>
</body></html>

주의:?callback=?를 참조해 주세요.이것은, 에 대해서getJSONJSONP를 사용하고 싶은 함수입니다.이 함수를 삭제하면 바닐라 JSON 요청이 사용됩니다.동일한 오리진 정책으로 인해 실패합니다.

자세한 내용과 예는 JQuery 사이트 http://api.jquery.com/jQuery.getJSON/에서 확인할 수 있습니다.

언급URL : https://stackoverflow.com/questions/2681466/jsonp-with-jquery

반응형