阿贾克斯后的特殊字符 [英] ajax post special characters
问题描述
我如何传递包含像'%'字符和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屋!