【问题标题】:jquery AJAX post data is not passed to server on chrome and firefox (Spring MVC - requestmapping)jquery AJAX 发布数据未在 chrome 和 firefox 上传递到服务器(Spring MVC - requestmapping)
【发布时间】:2013-12-05 08:05:53
【问题描述】:

我正在尝试通过 jquery ajax 使用 http post 方法将数据发送到服务器。

客户端javascript的代码在这里。 (jquery版本为v1.7.1)

$.ajax({
  type : "POST",
  async : false,
  url : "/my/context/and/path.html",
  data : "key1=value1&key2=value2",
  dataType : "json",
  contentType: "application/x-www-form-urlencoded; charset=utf-8",
  cache : false,
  crossDomain: true,
  success : function(data) {
    alert("success");
  },
  error : function(xhr, textStatus) {
    alert("error");
  }
});

服务器端代码在这里。

@RequestMapping(value="/my/context/and/path.html")
    public void createSomeData(
            MyVo myVo,
            HttpSession session,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {

            logger.debug("user id -vo : " + myVo.getUserId());
            logger.debug("user id -request : " + request.getParameter("userId"));
}

当我将 Mac 与任何浏览器一起使用时,它都能正常工作。 (记录器写入适当的用户 ID)。 即使我使用的是 Windows 7,它在 IE8 上也能正常工作。

但是问题是我使用的时候请求参数没有传递 Windows7 上的 chrome 或 firefox。

此外,我必须在其中部署相同的 Web 应用程序的环境。 一种是使用 https,另一种是使用 http 作为 Web 服务器。

我之前提到的问题只发生在使用 https(SSL) 的 Web 服务器上。

谁能帮我解决这个问题。

提前致谢。

【问题讨论】:

    标签: ajax spring google-chrome post https


    【解决方案1】:

    在 chrome 中,您可以使用 firebug lite 调试工具,以便您可以准确地看到在 chrome 上发出请求时发生的情况。

    http://getfirebug.com/releases/lite/chrome/

    【讨论】:

    • 是的。我尝试使用 firebug 进行调试。它说 xhr.send( ( s.hasContent && s.data ) || null ); jquery-lastest.js 行。因此,尽管调用了服务器方法,但请求没有参数事件。
    • @HosangJeon 可能是 jquery 的版本在 chrome 上创建问题或在方法调用中传递了一些错误的值
    【解决方案2】:

    我用 Firefox 24. jQuery v1.7.2 尝试了你的代码。它工作正常。

    【讨论】:

    • 问题的原因似乎是请求正文的长度(5KB)。我在删除大量输入标签后进行了测试,即使在 chrome 和 firefox 中也能正常工作。网络浏览器中的帖子正文大小是否有任何限制?
    【解决方案3】:

    最后还是没找到确切的解决方案,但可能与一些请求参数有关。

    在我去掉了一些不必要的参数后,它工作正常。

    还是很奇怪的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 2017-12-09
      • 2017-09-09
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多