I’m thinking about using something like:
<script src="http://www.example.com/?key={"param":"value"}">
As you can see in the example above a JSON formatted string is being passed over the src URL. The example, of course, doesn’t work because both the JSON string and the script tag use double quotes.
Here are a few solutions that I can think of:
-
Use single quotes in the script tag. The problem – doesn’t look good in a page where all other tags use double quotes.
-
Use
"instead of “. The problem – makes the src URL hard to read. -
Use an alternative to JSON data interchange format that doesn’t use double quotes. The problem – I can’t think of a good candidate.
What do you think?
You should use encodeUriComponent and then decode the value on the server (what language are you using on the server?).