如何接收特殊字符?特殊字符

由网友(人间失格)分享简介:我发送以下数据来自textarea的:I am sending below data from textarea:<?phpfor ($x=0; $x 但是,当我得到的数据从客户端上的服务器时,它变得像下面。它会把 +...

我发送以下数据来自textarea的:

I am sending below data from textarea:

<?php
for ($x=0; $x<=10; $x++)
  {
  echo "The number is: $x <br>";
  }
?> 

但是,当我得到的数据从客户端上的服务器时,它变得像下面。它会把 +

征是特殊字符。

<?php
for ($x=0; $x<=10; $x)
  {
  echo "The number is: $x <br>";
  }
?>

如何获得数据,因为它被送到?

How to get data as it is sent?

推荐答案

通过HTTP GET提交原始输入用加号将导致加号无法发送。这是一个保留字符。 在这里看到。

Submitting raw input with a plus sign via HTTP GET will cause the plus sign to not be sent. It is a reserved character. See here.

您老code内置的GET请求用手像这样:

Your old code built the GET request by hand like so:

var code = "code=" + code;
$.ajax({
  // ...
  data: code,
  /// ...
});

但你从来没有使用过连接codeURIComponent(code),从而使您的加号流失到规范的张开下颌。

But you never used encodeURIComponent(code), thus causing your plus signs to be lost to the gaping jaws of the specification.

var code = "code=" + encodeURIComponent(code);

jQuery将自动但如果你传递一个简单的对象,做到这一点。构建URLs是烦人,所以这是我的模式preFER:

jQuery will do this automatically though if you pass it a plain object. Building urls is annoying, so this is the pattern I prefer:

$.ajax({
  // ...
  data: {
    code: code
  },
  /// ...
});
阅读全文

相关推荐

最新文章