Servlet无法从ajax请求中获取参数

时间:2016-10-25 12:14:09

标签: java jquery ajax jsp servlets

我在JSP中有一个AJAX请求,它有其他嵌套的AJAX请求。

AJAX位:

var boxval = new Array();
boxval = getcheckval();
for (var i = 0; i < boxval.length; i++) {
  $.ajax({
      type: "get",
      url: "myservlet",
      beforeSend: function() {
        $('#text1')
          .css({
            "color": "red"
          });
        $('#text1')
          .text(
            "Running Graph");
      },
      data: {
        "boxval": boxval[i]
      },
      success: function(
        responseText) {
        $('#text1')
          .css({
            "color": "green"
          });
        $('#text1')
          .text(
            responseText);
      },
      complete: function() {
        $.ajax({
            type: "get",
            url: "ConnectServlet",
            beforeSend: function() {
              $('#text2')
                .css({
                  "color": "red"
                });
              $('#text2')
                .text(
                  "Copying Files and preparing pSet");
            },
            data: {
              val: boxval[i]
            },
            success: function(
              responseText) {
              $('#text2')
                .css({
                  "color": "green"
                });
              $(
                  '#text2')
                .text(
                  responseText);
            },
            complete: function() {
              $.ajax({
                  type: "get",
                  url: "CopyServlet",
                  beforeSend: function() {
                    $('#text3')
                      .css({
                        "color": "red"
                      });
                    $('#text3')
                      .text(
                        "Running Dynamic Diff Graph");
                  },
                  data: {
                    box: boxval[i]
                  },
                  success: function(
                    responseText) {
                    $('#text3')
                      .css({
                        "color": "green"
                      });
                    $('#text3')
                      .text(
                        responseText);
                  },
                  complete: function() {
                    $('#summary')
                      .show();
                  }
                });
            }
          });
      }
    });
}

在我的第一个AJAX请求中,servlet能够接收我作为参数发送的数据:

data : {
            "boxval" : boxval[i]
        },

String graphName=request.getParameter("boxval");

但是在我所有嵌套的ajax请求中,servlet都无法接收我作为参数发送的数据:

data : {
           "val" : boxval[i]
       },

String graphName=request.getParameter("val");

参数返回null。

为什么会这样?我做错了什么?

0 个答案:

没有答案