如何接收特殊字符? [英] How to receive special character?

查看:169
本文介绍了如何接收特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送以下数据来自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
  },
  /// ...
});

这篇关于如何接收特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆