1. 程式人生 > >SpringMVC下ajax提交form表單與後臺接收

SpringMVC下ajax提交form表單與後臺接收

==========jsp(input 的name必須和實體名稱一致)==================

<form method="post" id="frmjob" name="frmjob" action=""> 

編號:<input name="id" type="text" />
    名稱:<input type="text" name="name"  />

    </form>

===========js==============

$.ajax({
    type : "POST",
    url : '/jubcrm/PubjobController/jobMgs.hml',
    data :  $("#frmjob").serialize(),//序列化表單提交input 值
    success : function(msg) {
alert(msg);       

 }
     },
    error : function(msg) {
     $.messager.alert(prompts(), "操作失敗");
    }
   }); 

========action後臺我這裡使用的是SpringMVC如果用ssh用法一致===============

@Controller
@RequestMapping("PubjobController")
public class PubjobController {
 @Autowired
 public PubjobServices pubjobServices;//業務層使用註解的方式

 //Pubjob  實體
 @RequestMapping("jobMgs")
 public String jobMgs(Pubjob job,HttpServletRequest request, HttpServletResponse response)
   throws IOException {
System.out.print(job.getId());

System.out.print(job.getName());   

response.getWriter().write("操作成功!");

    response.getWriter().close();

  return null;
 }