0

这是我的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()没有被调用。

请帮助解决问题?

4

1 回答 1

1

将 ajax 调用的数据部分中的 json 字符串化并添加 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();
    }
});
于 2013-10-28T13:42:35.190 回答