IT 소식

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
<form id="fm" name="fm" method="post">
<input type="hidden" name="userId" id="userId" value="test1234">
<input type="hidden" name="userPass" id="userPass" value="pass1234">
축구:<input type="checkbox" name="type" id="type" value="축구">
야구:<input type="checkbox" name="type" id="type" value="야구">
농구:<input type="checkbox" name="type" id="type" value="농구">
</form>
<button onclick="goAjax1();">goAjax1</button>
<button onclick="goAjax2();">goAjax2</button>
<button onclick="goAjax3();">goAjax3</button>
<button onclick="goAjax4();">goAjax4</button>
<button onclick="goAjax5();">goAjax5</button>
<button onclick="goAjax6();">goAjax6</button>
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
function goAjax6(){
   
  var checkValues = new Array();
  $("input[name='type']:checked").each(function(){
    checkValues.push($(this).val());
  });
   
  var data = {"userId": $("#userId").val(), "userPass":$("#userPass").val(), "type":checkValues };
   
  $.ajax({
    type: "POST",
    url : "<c:url value="/goAjax6.do">",
    data : JSON.stringify(data),
    dataType: "json",
    contentType:"application/json;charset=UTF-8",
    async: false,
    success : function(data, status, xhr) {
      console.log(data);
    },
    error: function(jqXHR, textStatus, errorThrown) {
      alert("error= " + errorThrown);
    }
  });
}
</c:url>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /**
   * @param JSON 데이터 받기
   * @return
   * @throws Exception
   */
  @RequestMapping(value = "/goAjax6.do", method = RequestMethod.POST)
  @ResponseBody
  public Map<string, object=""> goAjax3(@RequestBody String param) throws Exception{
     
    JSONObject json = JSONObject.fromObject(param);
    System.out.println("userId:"+json.get("userId"));
    System.out.println("userPass:"+json.get("userPass"));
    System.out.println("type:"+json.get("type"));
     
    JSONArray array = (JSONArray) json.get("type");
    for(int i=0; i<array.size(); i++){="" system.out.println("array:"+array.get(i));="" }="" map<string,="" object=""> map = new HashMap<string, object="">();
    map.put("AA", "1");
    map.put("BB", "2");
    return map;
  }
 
</string,></array.size();></string,>

'프로그래밍 > Spring' 카테고리의 다른 글

Ajax JSON Map 타입으로 넘기고 받기  (0) 2018.01.30
전자정부 프레임워크 Ajax 설정  (0) 2018.01.09
Spring properties 설정방법  (0) 2017.10.26