Ajax的使用

A:在jsp里的<script>标签里写上:

 

function ajaxFunction(value) {
$.ajax({
url : "add",//这里是提交到哪去
data : {
"productId" : $("#select option:selected").val()//数据

},
type : "post",
contentType : "application/json;charset=UTF-8",//编码
success : function(msg) {
//回调函数
alert("添加成功!");
}
})
}

 

 

B:

 

在控制器的方法括号里写上对应的类型的同名的变量作参数,就可以直接在方法体内拿来用了,如:

 

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(Sale s, Model m, String productId,HttpSession hSession, HttpServletRequest req, HttpServletResponse resp) {

 }