Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery/javascript:如何接受特殊字符并使用json通过ajax发送?_Jquery_Ajax_Json_Character Encoding_Special Characters - Fatal编程技术网

jQuery/javascript:如何接受特殊字符并使用json通过ajax发送?

jQuery/javascript:如何接受特殊字符并使用json通过ajax发送?,jquery,ajax,json,character-encoding,special-characters,Jquery,Ajax,Json,Character Encoding,Special Characters,我试过btoa() 但是它不能正确地处理移动角色 我也使用了encodeURIComponent(),但它会使字符串变长,并且json在发送数据时有256个字符的限制,所以这是个问题 什么是正确的解决方案?谢谢首先,json不限于256个符号。我想您是通过GET方法发送数据的——它的长度有限,可能会阻止您发送特殊字符 解决方案可以让我使用POST方法代替GET。 只需使用: jQuery.post('http://you-url-here',{ 'data': 'string-with

我试过btoa()

但是它不能正确地处理移动角色

我也使用了
encodeURIComponent()
,但它会使字符串
变长
,并且json在发送数据时有256个字符的限制,所以这是个问题


什么是正确的解决方案?谢谢

首先,json不限于256个符号。我想您是通过GET方法发送数据的——它的长度有限,可能会阻止您发送特殊字符

解决方案可以让我使用POST方法代替GET。 只需使用:

jQuery.post('http://you-url-here',{
    'data': 'string-with-special-chars',
    ....
},function(res){ ... },'json');

或者使用jQuery.ajax()方法几乎相同。

带有特殊字符的字符串不起作用,因为它包含&,所以它作为查询字符串通过POST发送它们将允许您使用“&”符号
jQuery.post('http://you-url-here',{
    'data': 'string-with-special-chars',
    ....
},function(res){ ... },'json');