Teresa
Teresa

Reputation: 127

How can I use json data with & symbol using json

I have tried with the following code:

$.get("/a.php?op=ajax&section=b&cat_name=" + name.replaceAll("%", "")) + "&a=" + aname.replaceAll("%", "_"),function(resp) {

});

In my name value contains more than one & symbol. 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.

Upvotes: 0

Views: 200

Answers (1)

Barmar
Barmar

Reputation: 781141

Use encodeURIComponent() to encode special characters in query parameters. If you do this, you also don't need to remove %, it will encode them properly.

$.get("/a.php?op=ajax&section=b&cat_name=" + encodeURIComponent(name) + "&a=" + encodeURIComponent(aname),function(resp) {

});

Upvotes: 1

Related Questions