【问题标题】:How to get parameter long html page string from request in java?如何从java中的请求中获取参数长html页面字符串?
【发布时间】:2014-08-27 15:00:19
【问题描述】:

我在 javascript 中发布请求。我在发布数据中发送 html 页面。在java中,我使用String html = request.getParameter("templateHtml");,当我处于调试模式时,我在请求中看到了html字符串。但是“html”变量为空。 我的 javascript 代码在这里:

var postData = {};
postData["templateHtml"] = "Html page's string is too long";
$.ajax({
    type: 'POST',
    url: createUrl,
    data: postData,
    success: function(data) {
      onSuccess(data);
    },
    error: function(message) {
      onFail(message);
    },
});

为什么我收到一个空的“html”变量?我该如何解决?

【问题讨论】:

  • “html”变量在哪里?
  • "String html = request.getParameter("templateHtml");"

标签: java javascript jquery html ajax


【解决方案1】:
var postData = {};
postData["templateHtml"] = "Html page's string is too long";
$.ajax({
    contentType: 'application/json',
    dataType: 'json',
    processData: false,
    type: 'POST',
    url: createUrl,
    data: JSON.stringify(postData),
    success: function(data) {
        onSuccess(data);
    },
    error: function(message) {
        onFail(message);
    },
});

我将我的帖子数据转换为 JSON。它现在正在工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    相关资源
    最近更新 更多