웹프로그래밍

Global It Leader!!


jQuery


 
 

Jsonp 크로스 도메인 jQuery, Ajax 예제

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 5,050회 작성일 12-02-29 18:18

본문

jsonp.php
====================jsonp.php 소스===================================
<html>
<head>
<title>JSONP 테스트</title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script language="javascript">
$(function(){
    $("#btn1").click(function(){
 $.getJSON('http://도메인/getJsonp.php', 'callback=?', function(data){
     $.show(data);
 });
    });
 
    $("#btn2").click(function(){
        $.ajax({
            url : 'http://도메인/getJsonp.php'
            , dataType : 'jsonp'
            , jsonp : 'callback'
            , success : function(data){
                $.show(data);
            }
            , error: function(xhr){
                $.show(xhr);
            }
        });
    });
   
    $.show = function(data){
        $.each(data, function(key, val){
            $("#jsonp").append("<div>"+key + " : " + val +"</div>");
        });
    }
 
});
</script>
</head>
<body>
    <button id="btn1">테스트getJSON</button>
    <button id="btn2">테스트ajax</button>
    <div id="jsonp"></div>
</body>
</html>

========== getJsonp.php 소스 ============================
<?php
header("Content-Type:text/html;charset=EUC-KR");
?>
<?
$callback = $_GET["callback"];
echo "$callback ({'key1':'어머니','key2':'아버지'})";
?>

댓글목록

등록된 댓글이 없습니다.

전체 142
게시물 검색
jQuery 목록
번호 제목 글쓴이 조회 날짜
122 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6031 06-09
121 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5979 06-13
120 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5885 06-13
119 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5765 04-24
118 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5680 05-13
117 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5585 05-26
116 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5508 08-21
115 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5485 04-24
114 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5480 08-27
113 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5309 04-28
112 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5308 03-09
111 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5261 03-15
110 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5058 07-11
109 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5052 07-26
열람중 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5051 02-29
107 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4967 02-28
106 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4903 02-29
105 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4873 11-23
104 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4869 04-24
103 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4857 08-21