Google Answers Logo
View Question
 
Q: Calling javascript function via Ajax ( No Answer,   0 Comments )
Question  
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>
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy