阿贾克斯后的特殊字符 [英] ajax post special characters

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

问题描述

我如何传递包含像'%'字符和AA的大弦'和; 通过AJAX后我的PHP页面?

How do I pass a a large string containing characters like '%' and '&' to my php page through ajax post?

在换句话说如何JavaScript的EN code他们和php-DE $ C C他们$?

In other words how to javascript-encode them and php-decode them?

推荐答案

连接codeURIComponent() JavaScript函数可以被用来逃避任何这些字符的无论是键或值。

the encodeURIComponent() JavaScript function can be used to escape any of those characters in either the keys or the values.

PHP将接受和去$ C $自动C时进 $ _ POST 阵列。

PHP will receive and decode it automatically into the $_POST array.

数据的格式应该是查询字符串格式,具体如下:

The format of the data should be Query String format, specifically:

Content-Type: application/x-www-form-urlencoded

例如:

Name=Joe&Age=23&City=Altoona

如果您使用连接codeURIComponent()每个键和每个值,然后加入他们用 = ,和他们组由&安培; ,你不会有任何进一步的问题

If you use encodeURIComponent() on each key and each value, then join them with =, and group them by &, you won't have any further issues.

这篇关于阿贾克斯后的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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