$('#prev').click(function(){
$.ajax({
cache: true,
type: "POST",
url: "TestPaperServlet?action=test",
data:$('#formId').serialize(), // 你的表单id
async: false,
error: function(request) {
alert("预览失败");
},
success: function(data) {
alert("预览成功");
}
});
});
如果是传json格式数据的话:
$(".a_post").on("click",function(event){
event.preventDefault(); // 使a自带的方法失效,即无法向addStudent.action发出请求
$.ajax({
type: "POST", // 使用post方式
url: "addStudent.action",
contentType:"application/json",
data: JSON.stringify({param1:value1, param2:value2}), // 参数列表,stringify()方法用于将JS对象序列化为json字符串
dataType:"json",
success: function(result){
// 请求成功后的操作
},
error: function(result){
// 请求失败后的操作
}
});
});