ajax提交代码
$(document).ready(function() {
$("#submit").click(function(e) {
e.preventDefault();
var obj = $(this);
var name = $("input[name='name']").val();
var phone = $("input[name='phone']").val();
$.ajax({
url : "userAsk",
type : "POST",
contentType : "application/x-www-form-urlencoded",
data : {name:name,phone:phone},
//dataType : "text",
success : function(result, status, req) {
$(".noticeInfo").css("display", "block");
},
error : function(req, status, reason) {
$(".noticeInfo").css("display", "block").text('Error:' + reason);
}
})
return false;
})
});
后台代码
@RequestMapping(value = "/test", method = RequestMethod.POST)
public String myTest(@RequestParam("name") String name,@RequestParam("phone") String phone, ModelMap model) { ……
return "ok";
}