|
|
Subject:
Calling javascript function via Ajax
Category: Computers > Internet Asked by: iclick-ga List Price: $10.00 |
Posted:
22 Nov 2006 14:37 PST
Expires: 22 Dec 2006 14:37 PST Question ID: 784921 |
I am new to Ajax and am wondering if following is feasible: I am using PHP to pull some html code from database on button click and then displaying it on the page. If the html code is actually javascript - it won't run. See below for example below. If you run it as is, it will work and a javascript alert will show up. If you remove the comments from the second $data= line, it won't run. I'll get javascript error saying that the go() function is not defined. My question basically is - is it possible to call and run javascript via Ajax like this? Thanks. <? require("Sajax.php"); function display() { $data = "<img src=\"://www.google.com/intl/en_ALL/images/logo.gif\" onload=\"alert('img alert');\">"; // $data = "<script>function go(){alert('function alert')};</script><img src=\"://www.google.com/intl/en_ALL/images/logo.gif\" onload=\"go();\">"; return $data; } sajax_init(); // $sajax_debug_mode = 1; sajax_export("display"); sajax_handle_client_request(); ?> <html> <head> <title>Ajax</title> <script> <? sajax_show_javascript(); ?> function do_display_cb(data) { document.getElementById("data").innerHTML = data; } function do_display() { x_display(do_display_cb); } </script> </head> <body> <input type="button" name="check" value="Display" onclick="do_display(); return false;"> <div id="data"> Data will appear here </div> </body> </html> |
|
There is no answer at this time. |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |