2017-03-29 18 views
0

私はLongとDoubleをSpringコントローラ用のAjaxに送信したいと思います。Ajaxを使用してLongとDoubleをSpringコントローラに送信する方法は?

var id = $(this).data('customer-id'); 
    var quantity = $('#quantity-' + id).val(); 
    $.ajax({ 
     headers: { 
      "Accept": "application/json", 
      "Content-Type": "application/json" 
     }, 
     type: "POST", 
     url: '/changeQuantityOrder', 
     data: {idOrder: id, quantityChange: quantity}, 

     error: function(e) { 
      console.log(e); 
     }, 
     success: function (msg) { 
      window.location.href = "/administrationNotSleeps"; 
     } 

私は、コードを受信しよう:私は見て、この例外(MissingServletRequestParameterException)https://stackoverflow.com/
について発見した。しかし、この

@RequestMapping(value = "/changeQuantityOrder", method = {RequestMethod.POST}) 
public @ResponseBody Long editCustomerOrder(@RequestParam(value = "idOrder")Long id, 
              @RequestParam(value = "quantityChange")Double quantity){  
    System.out.println("Id:"+id+" Quantity "+quantity); 
    return id; 
} 

しかし、私は例外

{"timestamp":1490775639761,"status":400,"error":"Bad Request","exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required Long parameter 'idOrder' is not present","path":"/changeQuantityOrder"}" 

を受け取ります記事は3年前に書かれた、多分何か変わった?
今はString to Springコントローラを送信してから、それ以降はjavaでsplitを使用します。

答えて

0

キーは引用符で囲む必要があります。data: {"idOrder": id, "quantityChange": quantity} また、dataType - どのような応答を期待しますか。

関連する問題