[英]How can I use json data with & symbol using json
I have tried with the following code:我尝试过使用以下代码:
$.get("/a.php?op=ajax§ion=b&cat_name=" + name.replaceAll("%", "")) + "&a=" + aname.replaceAll("%", "_"),function(resp) {
});
In my name
value contains more than one &
symbol.在我的
name
中,值包含多个&
符号。 At that time I couldn't pass the full value because of when one &
symbol occur then, it breaks my data.那时我无法传递完整的值,因为当出现一个
&
符号时,它会破坏我的数据。 For example my name = 'DisplayPort & Mini DisplayPort Connector'
I got only 'DisplayPort'.I didn't get the remaining part.例如,我的
name = 'DisplayPort & Mini DisplayPort Connector'
我只得到了 'DisplayPort'。我没有得到剩余的部分。
Use encodeURIComponent()
to encode special characters in query parameters.使用
encodeURIComponent()
对查询参数中的特殊字符进行编码。 If you do this, you also don't need to remove %
, it will encode them properly.如果你这样做,你也不需要删除
%
,它会正确编码它们。
$.get("/a.php?op=ajax§ion=b&cat_name=" + encodeURIComponent(name) + "&a=" + encodeURIComponent(aname),function(resp) {
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.