Ajax工作不正常?

时间:2013-10-28 13:25:27

标签: jquery ajax servlets

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

请帮忙解决问题?

1 个答案:

答案 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();
    }
});