2

I am using php to json encode an array and then parse it with jQuery's $.evalJSON()

to use it in the client side

$test = array(
    'Label' => array(
        'id' => '021780000002703007764835',
        'notes' => '<a id="test" href="javascript:void(0)">ici</a>'
    )
);

When encoded to json from php it produces

{"Label":{"id":"021780000002703007764835","notes":"<a id=\"test\" href=\"javascript:void(0)\">ici<\/a>"}}

However, when using the below js code to decode it I get a js error

var test = $.evalJSON('<?= $test; ?>');

When I remove the html markup, it decodes it fine. However, I need the markup and I am sure there is a way to decode it properly.

Any ideas?

Thanks

1
  • can you print the instruction once it has been processed by php ? that could be an escaping problem Commented Feb 8, 2011 at 10:12

1 Answer 1

3

Try this

 addslashes(json_encode($test));

I have successfully used this in the past for exactly this problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.