Live Brilliant

crossdomain jsonp 사용 본문

개발은 핵찜이야/AJAX

crossdomain jsonp 사용

주인정 2013. 11. 14. 14:14

        var formData = $('#addonFrm').serialize();

        /* 일반적인 ajax통신

        $.ajax({

            type: "post",

            url: "userdb.php",

            timeout: 10000,

            data: formData,

            cache: false,

            crossdomain: true,

            dataType: "jsonp",

            success: function(data){

                console.log('success!!');

                console.log(data);

            },error: function(){

                console.log('error!!');

            }

            

        });

        

        //crossdomain 이 적용된 도메인 jsonp

        $.ajax({

            url: 'userdb.php',

            type: 'GET',

            data: formData,

            dataType: "jsonp",

            jsonp: "callback",            

            success: function (data) {

                console.log(data);

            },

            error: function (xhr, ajaxOptions, thrownError) {

               console.log('on error!');

            }

        });




[php]

$data = array(

'test'=>'test data',

);

echo $_GET['callback'].'('.json_encode($data) .')';

'개발은 핵찜이야 > AJAX' 카테고리의 다른 글

jquery ajax load more 더보기 기능  (0) 2013.01.03
ajax json 엔터값 로드 문제  (0) 2012.12.17
ajax CDATA  (0) 2012.05.30
Comments