jquery를 공부하면서 느낀건데
API가 너무 잘 되어 있음....ㅡ.ㅡv

API : jQuery.ajax()
API : .serialize()

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="false" %>   
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
<title>jQuery Test Page</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
</head>
<body style="padding:10px;">
<div>
    <form name="userForm" method="post">
    <table border="1">
        <tr>
            <td>이름</td>
            <td><input type="text" name="name"/></td>
        </tr>
        <tr>
            <td>나이</td>
            <td><input type="text" name="age"/></td>
        </tr>
        <tr>
            <td>지역</td>
            <td><input type="text" name="location"/></td>
        </tr>
    </table>
    <input type="button" name="submit" value="전송"></input>
    </form>
</div>

<script type="text/javascript">
$(document).ready(function(){
    $("input[type='button']").click(function(){
        //보통 data를 보낼시 name=aaa&age=bbb&location=ccc
        //이런식으로 직접 작성할 경우가 있는데 그럴경우 하단처럼 처리하면 한번에 처리 됨
        //하단의 결과 =>>> name=aaa&age=bbb&location=ccc
        //var $form = $("input[type!='button']").serialize();
        //var $form = $("input").serialize();
        var $form = $("form").serialize();
   
        $.ajax({
            type:"post",
            data:$form,
            url:"jsp/jQuery/data.html",
            success:function(json){
                var pData = jQuery.parseJSON(json);
                alert(pData.msg);
            }
        });
    });
   
});
</script>       
   
</body>
</html>

'프로그램 > jQuery' 카테고리의 다른 글

when() 함수로 동기처리 하기  (0) 2013.09.05
jqGrid  (0) 2012.03.22
Ajax - jQuery.parseJSON()  (0) 2012.03.14
traverse(탐색)  (0) 2012.03.13
filter  (0) 2012.03.13

+ Recent posts