): jsFidd..." />

Pass associative array from php to javascript [closed]?

JSON is perfect: User pst brought up these concerns: "array("") -- darn, just broke this "perfect" approach. " It seems to work because ( => ): jsFiddle "What about > which could occur in XHTML? "The string is able to be transferred.

JsFiddle Update: In regards to debugging the problem with the JS: Are there any errors in the console? One of your document. GetElementById(...) might be returning a null.

Therefore the member value doesn't exist.

Thanks @cdhowie, I usually try to have complete code O_o – afuzzyllama Aug 27 at 20:15 No problem, just trying to make the code clearer. :) +1 too, this is the right approach. – cdhowie Aug 27 at 20:16 This is not very happy when "" appears in the JSON.

While JSON is a subset of JavaScript literals, not all JavaScript literals are valid in a element (and I'm ignoring XHMTL entirely). I really wish there was a function designed just to facilitate this particular use-case with it's little caveats. – pst Aug 27 at 20:23 I am doing the same thing.

Json_encode function. But with a small difference, I am passing array of php to js by calling a function. And the function is not working.

I just used alert() in the calling funcition to check if value is received. But nothing happened. – Abhimanyu1310 Aug 27 at 20:25 1 This is perfectly safe, even if the string contains .

PHP's json_encode escapes the / for this purpose. – arnaud576875 Aug 27 at 20:56.

I always believed JSON were invented for this: This will render like this: Safeness This is perfectly safe for javascript, as JSON is a subset of the javascript syntax. This means that any JSON string can be treated as Javascript. PHP's json_encode() is perfectly safe when embedding JSON in '); => "" So it's not possible to write , which is the only way to escape a tag.(Everything in a tag is part of the script, it's not parsed as HTML.) JSON allows to escape the / for this purpose.

So no JSON string can escape a tag.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions