views:

30

answers:

2

I'm sending some html via jQuery, and in this html are various values that need to be quoted, and in one instance, there's a nested value, so I have to be able to send both kinds of quotes. Here's some mock code:

var myVar = "<tag value='foo' value2="config={'bar':null, 'foo2':true}" />";

How can in ensure that the double quotes are sent properly?

+2  A: 

You can escape them.

var myVar = "<tag value='foo' value2=\"config={'bar':null, 'foo2':true}\" />";
t3hb4tman
See, that's the confusing thing. I tried escaping them, to no avail. I'm using jQuery to reload a div which contains a video player (which itself has flash fallback so I can stream m4v's in FF). The code to swap the div contents works in Chrome, and the fallback code works in FF, when hard coded (here's an example hardcoded: http://www.roestudios.com/dump/tester-hard.html in FF, video streams fine). But moving the exact same snippet to my little jQuery snippet so I can reload dynamically, and escaping the quotes... nadda. You can see that example here http://www.roestudios.com/dump/tester.html
Benjamin Allison
+1  A: 

you can escape the double quotes inside the string, by adding a slash in front of it.

like this

"some text \" more text"
Aaron de Windt