这是我的ajax代码
$('.AllTaskDownloadButton').live('click', '.CheckBoxesForDownload', function(){
var n = $( "input:checked.CheckBoxesForDownload" ).length;
var arr=[]
for(i=0;i<n;++i){
arr.push($($( "input:checked.CheckBoxesForDownload" )[i]).val())
}
alert(arr)
//passing requestId to servlet
$.ajax({
url:"/test/DownloadDeleteTask",
type:"POST",
dataType:'json',
data: {requestIds:arr,
operationType:'download' },
success:function(result){
alert(result);
dowloadTasks();
}
});//ajax
});
这是我的servlet代码:
PrintWriter out = response.getWriter();
String operationType = request.getParameter("operationType");
if (operationType.equalsIgnoreCase("download")) {
out.print("download");
}// if
但我的downloadTasks()
没有被调用。
请帮忙解决问题?
答案 0 :(得分:1)
将json字符串化为ajax调用的数据部分并添加contentType:
$.ajax({
url: "/test/DownloadDeleteTask",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({requestIds:arr,
operationType:"download"
}),
success:function(result){
alert(result);
dowloadTasks();
}
});