웹프로그래밍

Global It Leader!!


jQuery


 
 

Ajax 배열, 리스트 데이터 넘기기 (jQuery)

페이지 정보

작성자 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 1,933회 작성일 22-03-26 16:22

본문

<!DOCTYPE html>
<html>
<head>
    <title>Fruit</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            
            $("#save").click(function() {
                //배열 선언
                var fruitArray = [];
                
                $('input[name="fruit"]:checked').each(function(i){//체크된 리스트 저장
                    fruitArray.push($(this).val());
                });
                
                var objParams = {
                        "user"      : $("#user").val(), //유저 저장
                        "fruitList" : fruitArray        //과일배열 저장
                    };
                
                //ajax 호출
                $.ajax({
                    url         :   "/checkTest/save",
                    dataType    :   "json",
                    contentType :   "application/x-www-form-urlencoded; charset=UTF-8",
                    type        :   "post",
                    data        :   objParams,
                    success     :   function(retVal){
 
                        if(retVal.code == "OK") {
                            alert(retVal.message);
                        } else {
                            alert(retVal.message);
                        }
                         
                    },
                    error       :   function(request, status, error){
                        console.log("AJAX_ERROR");
                    }
                });
                
            })
            
        });
    </script>
</head>
<body>
    <table border="1">
        <tr>
            <td>
                <input type="checkbox" name="fruit" value="apple">
            </td>
            <td>
                apple
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="fruit" value="banana">
            </td>
            <td>
                banana
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="fruit" value="peach">
            </td>
            <td>
                peach
            </td>
        </tr>
    </table>
    <br>
    <input type="text" id="user" value="huskdoll">
    <button type="button" id="save">SAVE</button>
</body>
</html>
 

댓글목록

등록된 댓글이 없습니다.

전체 142
게시물 검색
jQuery 목록
번호 제목 글쓴이 조회 날짜
22 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2175 06-25
열람중 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1934 03-26
20 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1921 05-28
19 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1921 03-26
18 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1892 08-04
17 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1771 03-27
16 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1668 03-26
15 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1596 03-26
14 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1499 03-26
13 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1461 03-26
12 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1409 03-26
11 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1324 03-27
10 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1322 03-26
9 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1298 03-26
8 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1293 03-28
7 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1290 03-31
6 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1280 03-27
5 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1278 03-27
4 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1251 03-26
3 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 771 12-07