ellisd5 Posted December 5, 2006 Share Posted December 5, 2006 I have some code which basically updates a section of the screen with new content.This new content contains some javascript in it. The javascript which is return by the ajax request does not work. So my question, is there a way to dynamicly refresh the event handlers or something else maybe to get the javascript returned to work.I know I could just have the javascript in the page that does the calling but there are 100's of screens it could call and therefore its not practical to do it this way.TIADale Quote Link to comment Share on other sites More sharing options...
ober Posted December 5, 2006 Share Posted December 5, 2006 Are you talking about full scripts or just like onclick() type calls? I'm pretty sure loading full scripts into a returned dataset will not work. Quote Link to comment Share on other sites More sharing options...
ellisd5 Posted December 5, 2006 Author Share Posted December 5, 2006 I'm talking about full scripts. I thought there was a way to load the script into memory or wherever it is its needs to be registered to beable to run.Is there not? Quote Link to comment Share on other sites More sharing options...
ober Posted December 5, 2006 Share Posted December 5, 2006 I would assume only on the initial page load before you make any AJAX calls. I'm not 100% certain on that, but I'm going to assume that you can't do it. Quote Link to comment Share on other sites More sharing options...
artacus Posted December 5, 2006 Share Posted December 5, 2006 The obvious answer is to save those functions in a seperate js file and include it in your pages.But I've done this before. Its a little fuzzy but I believe I used eval(). Quote Link to comment Share on other sites More sharing options...
cruzonover Posted January 15, 2007 Share Posted January 15, 2007 I'm having the same issue. Can you describe how you used the eval() statement? Did you use it from the main page that contains the div tag where pages called by ajax are loaded, or is it in the called page? Quote Link to comment Share on other sites More sharing options...
vincea Posted January 16, 2007 Share Posted January 16, 2007 I'm having the same problem.. i think.I have an index page and I have links for "members" in the navbar. When a link is pressed the member info with AJAX is loading into a container on the index.php, the data in the container (member.php) contains javascript with both includes and some script in it. Javascript won't work for me either.I even tried running a Thickbox (Cody Lindley's Thickbox) from the link but it won't run the javascript either. ??? Quote Link to comment Share on other sites More sharing options...
artacus Posted January 25, 2007 Share Posted January 25, 2007 [quote]I'm having the same issue. Can you describe how you used the eval() statement? Did you use it from the main page that contains the div tag where pages called by ajax are loaded, or is it in the called page?[quote]No, its in the calling page. Try this:[code]--called_page.php<?php echo "alert('Whats up doc?');"?>--calling_page.php<script language='javascript'>function doSomething() { var ajaxResponse = getData('called_page.php'); //this doesn't do anything because its just a string eval(ajaxResponse); //will alert "Whats up doc?"}[/code] Quote Link to comment Share on other sites More sharing options...
impulse() Posted January 30, 2007 Share Posted January 30, 2007 Hello.I am having the same problem. I'm unable to use the eval function to work around it though. Reason being is that I have a PHP file which queries a MySQL database and if the results meet a certain criteria then I need it to run some Javascript.My situation is that I have a PHP file which contains AJAX code which runs another PHP file every few seconds. The PHP code that is run from AJAX queries a MySQL database and if certain results are returned I need there to be a Javascript popup window (alert()) appear. But as you're aware, AJAX doesn't evaluate Javascript. Hopefully you could help me out here, my code is as follows:[b]index.php[/b][code]<html><head><script type="text/javascript">function createRequestObject() { var ro; var browser = navigator.appName; if(browser == 'Microsoft Internet Explorer') { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else { ro = new XMLHttpRequest(); } return ro;}var http = createRequestObject();function sndReq(action) { http.open('get', 'reminderDisplay.php'); http.onreadystatechange = handleResponse; http.send(null);}function handleResponse() { if(http.readyState == 4) { var response = http.responseText; document.getElementById('foo').innerHTML = response; }}setInterval('sndReq()', 1000);</script></head><body><div id="foo"></div></body></html>[/code]Then I have the code that index.php runs:[b]reminderDisplay.php[/b][code]<?php// MySQL query here //// Results stored here //// If results = something then { Run Javascript (alert('Reminder active')) }?>[/code]How could I achieve this? Regards, Stephen Quote Link to comment Share on other sites More sharing options...
mainewoods Posted January 31, 2007 Share Posted January 31, 2007 read my post I just made to this thread:http://www.phpfreaks.com/forums/index.php/topic,123645.0.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.