728x90
    
    
  반응형
    
    
    
  
1. AJAX 배열(array) 전송시 주의사항
- traditional : true 설정하기
- Java Controller - getParameterValues로 받기
2. AJAX 사용법 간단 예제 코드
JSP 부분
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var url = "ajax_test.dh";    // Controller로 보내고자 하는 URL (.dh부분은 자신이 설정한 값으로 변경해야됨) var sendMsg = ['a','b','c']; console.log("JSP에서 보낸 MSG : " + sendMsg); $.ajax({     url : url,                    // 전송 URL     type : 'POST',                // GET or POST 방식     traditional : true,     data : {         sendMsg : sendMsg        // 보내고자 하는 data 변수 설정     },     //Ajax 성공시 호출      success : function(data){         console.log("컨트롤러에서 받은 MSG : " + data);     },     //Ajax 실패시 호출     error : function(jqXHR, textStatus, errorThrown){         console.log("jqXHR : " +jqXHR +"textStatus : " + textStatus + "errorThrown : " + errorThrown);     } }); http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter | 
크롬 Console창에서 확인하기

Controller 부분
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @RequestMapping(value = "/ajax_test.dh") @ResponseBody public String ajaxTest(HttpServletRequest request) {     String[] ajaxMsg = request.getParameterValues("sendMsg");     int size = ajaxMsg.length;     for(int i=0; i<size; i++) {         System.out.println("JSP에서 받은 MSG : "+ajaxMsg[i]);     }     String resultMsg = "AJAX Success";     System.out.println("Controller에서 보낸 MSG : "+ resultMsg);     return resultMsg; } http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter | 
Java Console 에서 확인하기

728x90
    
    
  반응형
    
    
    
  'Front > jQuery' 카테고리의 다른 글
| [jQuery] AJAX 동기 처리 Example (0) | 2019.07.21 | 
|---|---|
| [jQuery] Click Event Example (0) | 2019.07.14 | 
| [jQuery] AJAX 한글깨짐 해결 Example (0) | 2019.06.23 | 
| [jQuery] AJAX Example (0) | 2019.06.22 | 
| [jQuery] Checkbox checked Example (0) | 2019.06.20 |