by "won't work" do you mean it's throwing errors? Or it doesn't inject the HTML or..?
–
SiGantengMar 19 '12 at 3:22

How does it 'not work'? JSON couldn't care less WHAT you're embedding within the string - it can be numbers, it can be text, it can be html. it doesn't matter, as long the JSON syntax rules are honored.
–
Marc BMar 19 '12 at 3:22

Amazing answer! That's the way to do it.
–
Antonio MaxSep 19 '13 at 18:31

I was having the same issue but I was almost to the solution. I was using json_encode($json, JSON_HEX_QUOT | JSON_HEX_APOS). Changing the JSON_HEX_APOS to JSON_HEX_TAG made my problems disappear!
–
PentagearMar 8 '14 at 3:46

Not sure why json_encode returns such weird string :s, is the json_encode a standard php library or an external library? I'm asking this because some servers don't have json_encode in their php installation... I tested on my local and using php internal json_encode and it works fine:

Thanks for this, but no it doesn't work. If I did this, then it won't alert at all.
–
planet xMar 19 '12 at 3:36

Do you have a test page on this? Easier if I could go through and test directly
–
SiGantengMar 19 '12 at 3:37

and yes it won't alert as dataType json would expect a valid json string, in which case "HELLO WORLD" isn't a valid json
–
SiGantengMar 19 '12 at 3:38

thanks, but none i don't have a test page for this. it's set on my local. I guess this concerns a malformed JSON because if I var_dump the json_encode it looks like a well-malformed JSON.
–
planet xMar 19 '12 at 3:44