in PHP I create this object that I convert to JSON and send to a JS client:
$arr = array("img"=>"http://www.myDomain.com/imgs/pic_1.jpg","data"=>"<p>This is a paragraph <a href='#' onclick='MyFunction('myParameter');'>My Link</a></p>");
I think I’m doing something wrong with quotes (check the function call) but at the moment, once injected in my HTML, MyFunction never gets called. Which is the right way to escape quotes in that situation?
EDIT: this is the resulting JSON:
{"img":"http:\/\/www.myDomain.com\/imgs\/pic_1.jpg","data":"<p>Paragraph: <a href='#' onclick='localFunction('parameter');'>Link<\/a><\/p>","length":2}
You have single quotes inside “onclick” but “onclick” itself is delimited with single quotes.
Try: