JS, HTML & CSS

AJAX 심플 예제~ json

관리자 | 2013.02.08 14:03 | 조회 13462

웹페이지

----------------------------------------

<!DOCTYPE html>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
    </head>
    <body>
        <div id="result"></div>
        <input type="text" id="msg" />
        <input type="button" value="get result" id="getResult" />
        <script>
            $('#getResult').click( function() {
                $('#result').html('');
                $.ajax({
                    url:'http://opentutorials.org/example/jquery/example.jquery.ajax.php',
                    dataType:'json',
                    type:'POST',
                    data:{'msg':$('#msg').val()},
                    success:function(result){
                        if(result['result']==true){
                          $('#result').html(result['msg']);
                        }
                    }
                });
            })
        </script>
    </body>
</html>

 

 

 

 

 

서버쪽 페이지

-----------------------------

<?
echo json_encode(array('result'=>true, 'msg'=>$_REQUEST['msg']));
?>

 

twitter facebook me2day 요즘
22개(2/2페이지)
JS, HTML & CSS
번호 제목 글쓴이 조회 날짜
2 [JQUERY] 동적 셀렉트박스 관리자 10696 2013.01.21 14:23
1 [JAVASCRIPT] 자바스크립트의 모든것 관리자 4631 2013.01.21 14:23
많이 본 글
댓글 많은 글