【问题标题】:Posting a value that contains too many charcters and & char发布包含太多字符和 & char 的值
【发布时间】:2015-10-07 14:33:37
【问题描述】:

我正在尝试使用以下代码将一些数据发布到 php 文件中。

var exam = document.getElementById("information").getAttribute("examid");
            var user = document.getElementById("information").getAttribute("userid");
            var question = document.getElementById("information").getAttribute("questionid");

            var xmlhttp;
            xmlhttp=new XMLHttpRequest();
            xmlhttp.open("GET","savevalue.php?examid="+exam+"&userid="+user+"&questionid="+question+"&content="+ editor.getValue(),true);
            xmlhttp.send();
            xmlhttp.onreadystatechange=function()
            {
               if (xmlhttp.readyState==4 && xmlhttp.status==200)
              {

              }
            }

但第一个问题是如果我发布的变量包含太多字符,则此方法会失败。其次,如果我发布的变量之一包含“&”字符,它也会失败。我应该用其他东西替换& 吗?

【问题讨论】:

  • 如果参数之一中的数据?这是什么意思?
  • 我不明白第一个问题...
  • 如果示例中的变量如 question 和 user 有太多的字符如 6000 个字符,它会失败。我的意思是如果 var user="123" (3 chracters) 没有问题,但如果它有更多像 6000,它失败了
  • 因为你应该使用post作为get有限制。

标签: javascript http-post


【解决方案1】:

如 cmets 中所述,请使用 POST 方法而不是 GET,因为 POST 允许在一条消息中包含更多数据/字符。

对于和号 (&) 也是如此,这是一个需要转义的特殊字符,或者您可以使用 & 表示法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    相关资源
    最近更新 更多