On Friday 10 February 2006 15:58, Robin Haswell wrote:
> Oh I see! Sorry. That seems, well, bloody interesting. I don't do
> anything like this at the moment (all AJAX) but I will consider that for
> the future. I do need a way to encapsulate a load of HTML inside a JS
> string accurately. At the moment's I'm just doing search/replace
> escaping of quotes and newlines.

yea, you could just find a JSON module for your programming language (I use 
perl's JSON module, works great) and drop it in, voila.

for here's some perl code:

#!/usr/bin/perl

use strict;
use JSON;

my @array = ("how", "are", "you", "doing", "today");
print objToJson([EMAIL PROTECTED]);

this outputs:
["how","are","you","doing","today"]

now if we make that array more complicated:
my @array = qw( how're "you" doing today? '"q/3\\#\${]}[ );
that outputs:
["how're","\"you\"","doing","today?","'\"q/3\\#\\${]}["]

it automatically escapes everything for you.  If you already have the object 
created in whatever language you want, just use some sort of JSON module to 
convert it to javascript for you.  real easy :)

-Jeremy

-- 
Jeremy Kitchen ++ [EMAIL PROTECTED]

In the beginning was The Word and The Word was Content-type: text/plain
  -- The Word of Bob.

Attachment: pgpf1Kuu9tFqS.pgp
Description: PGP signature

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to