by Nathan

jSon ajax 본문

Programming/JavaScript, Json

jSon ajax

넷쓴 2015. 5. 10. 11:51

1. js (client)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
jQuery(document).ready(function($){
    
      
    //버튼
    $("#btn_test").click(function(){
        
        var bSubmit = true;
        
        if(bSubmit){
            $.ajax({
                url : '/test/testJson',
                type : 'POST',
                data : { 
                        param1 : "abcd"
                        param2 : $("#param2").val(),
                        param3 : $("#param3").val()
                        },
                dataType : "json",
                success : function(data) {
                    if(data == 0){
                        alert("0입니다");
                    }else{
                        alert("0이 아닙니다.");
                        testForm.submit();
                    }
                },
                error : function() {
                    alert('error');
                }
            });//end of ajax
        }
    });
 
      
});

cs

 

 

2. java (Server)

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@RequestMapping(value = "/testJson", method = RequestMethod.POST)
    public @ResponseBody int testJson(
            HttpServletRequest request,
            @RequestParam(value="param1", defaultValue="")String param1,
            @RequestParam(value="param2", defaultValue="")String param2,
            @RequestParam(value="param3", defaultValue="")String param3) throws Exception{
        
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /testJson 진입");
        
        Integer count = null;
        TestDTO testDTO = new TestDTO();
        
        testDTO.setParam1(param1);
        testDTO.setParam2(param2);
        testDTO.setParam3(param3);
 
        try {
            count = testService.countTest(testDTO);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
 
 

cs

'Programming > JavaScript, Json' 카테고리의 다른 글

반복문 4가지  (0) 2017.03.17
테이블 동적 생성  (0) 2016.10.25
[유효성]필수값 체크  (0) 2016.09.06
[유효성]자바스크립트 함수  (0) 2016.09.05
현재 URL 확인하기  (0) 2016.01.12
Comments