웹프로그래밍

Global It Leader!!


jQuery


 
 

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

페이지 정보

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

본문

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 목록
번호 제목 글쓴이 조회 날짜
42 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4560 03-21
41 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4485 03-21
40 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5269 03-15
39 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4648 03-15
38 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5316 03-09
37 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4703 03-08
36 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4377 03-08
35 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4722 03-01
34 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4544 03-01
33 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5060 02-29
열람중 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4913 02-29
31 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4506 02-29
30 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4974 02-28
29 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4596 02-27
28 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4862 02-22
27 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4344 02-26
26 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4444 02-14
25 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4383 02-10
24 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4880 11-23
23 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5487 08-27