웹프로그래밍

Global It Leader!!


jQuery


 
 

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

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 5,049회 작성일 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 목록
번호 제목 글쓴이 조회 날짜
62 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4056 11-29
61 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6629 09-17
60 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5507 08-21
59 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4855 08-21
58 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6418 07-13
57 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5977 06-13
56 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5308 04-28
55 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5484 04-24
54 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4868 04-24
53 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5765 04-24
52 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4826 04-24
51 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4391 04-20
50 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4020 04-19
49 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4383 04-19
48 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4030 04-17
47 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4343 04-11
46 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4409 04-01
45 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4575 04-01
44 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4276 03-31
43 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4344 03-22