Google Answers Logo
View Question
Q: Calling javascript function via Ajax ( No Answer,   0 Comments )
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

My question basically is - is it possible to call and run javascript
via Ajax like this?



   function display() { 
      $data = "<img src=\"://\"
onload=\"alert('img alert');\">";
      // $data = "<script>function go(){alert('function
      return $data;    
   // $sajax_debug_mode = 1; 
   function do_display_cb(data) { 
      document.getElementById("data").innerHTML = data; 
   function do_display() { 

   <input type="button" name="check" value="Display"
onclick="do_display(); return false;">
<div id="data"> 
Data will appear here 
There is no answer at this time.

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 with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

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