AJAX异步提交form表单

比如说有如下form:

 

        

发送异步请求提交form:

 
  1. function save(){

  2.  
  3. $.ajax({

  4. url:'debt/saveNew.do'+'?t='+Math.random(),

  5. data:$('#form1').serialize(), //将表单数据序列化,格式为name=value

  6. type:'POST',

  7. dataType:'json',

  8. success:function(data){

  9. //success

  10. },

  11. error:function(){

  12. console.log("提交ajax函数异常");

  13. },

  14.  
  15. });

  16. }

 

 

 

获取(能从param中取到值意味着怎么接收都可):

 
  1. @RequestMapping(value = "saveNew")

  2. //@Token(remove=true)

  3. public void saveNew(

  4. HttpServletRequest request,HttpServletResponse response){

  5. response.setContentType("application/json; charset=UTF-8");

  6. try {

  7. String submitTime = request.getParameter("submitTime");

  8. String receiverId = request.getParameter("receiverId");

  9. String isRegister = request.getParameter("isRegister");

 

你可能感兴趣的:(AJAX异步提交form表单)