0

I am using PHP to send a json string to jQuery ajax. I am simply using $("#id").html(data.result) to display the html from the fetched page. Now on the fetched page I am looping through MySQL results. I need to run a piece of javascript on each result so I can start a countdown timer for each result.

My problem is that the calling page simply displays the actual javascript script as a string.

$row_array['result'] .= '<script>trigger script</script>'

Any suggestions?

Thanks

1
  • I think that we're going to need more information. A sample of the returned JSON from your script AND the JavaScript that you're running. How have you tried to implement it already? Commented Oct 30, 2011 at 8:59

1 Answer 1

1

If part of data.result is javascript, it is not executed. Try this:

$script = 'alert("this is javascript");';
$html = '<b>blah blah this is html<b>';
$row_array['result'] = json_encode(array('script' => $script, 'html' => $html));

and then instead $("#id").html(data.result) use:

eval(data.result.script)
$("#id").html(data.result.html)
Sign up to request clarification or add additional context in comments.

1 Comment

Though using eval is evil... sometimes it is the only way. if you show us your code we might be able to help more...

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.