alapimba Posted November 6, 2007 Share Posted November 6, 2007 Hello I'm doing an http request of one page, and when that page loads the javascripts on that page don't work. theres anyway to fix this? my request code is: function replace<?php echo $row_rs_anos['id']; ?>() { http.open("GET", "simple_accordions_with_src/Basic.html", true); http.onreadystatechange=function() { if(http.readyState == 4) { document.getElementById('foo').innerHTML = http.responseText; } } http.send(null); } anyone can help me? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted November 7, 2007 Share Posted November 7, 2007 javascripts retrieved with ajax and then innerHTML'ed into something will not execute! There is no 'simple trick' to fix that. The problem is not with ajax, but with innerHTML, it just doesn't have the capabilities. If you want javascripts retrieved from ajax to execute, then you must separate those javascripts out of what was returned and then run them through the javascript eval() function. Quote Link to comment Share on other sites More sharing options...
alapimba Posted November 8, 2007 Author Share Posted November 8, 2007 humm can you help me a bit more specificly please? forget about the script that i show before, i allready found an way to turn around the display and its working. now i just need the script lightbox to work. i have this link to the js script: <script type="text/javascript" src="javascript/lightbox.js"></script> the script is trigered with this code (rel="lightbox") <a href="img/galeria/2.jpg" rel="lightbox" title="untitled. mixed media on canvas. 100 x 180 x 12 cm. 2006."><img src="img/galeria/thumb_2.jpg" alt="" width="66" height="90" border="0" /></a> How can i do that eval thing? ??? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted November 8, 2007 Share Posted November 8, 2007 <script type="text/javascript" src="javascript/lightbox.js"></script> --you cannot eval() a script with a src= returned through ajax. You can only eval straight javascript statements: ajaxreturn = "var a=8;alert(a);"; eval(ajaxreturn); --just include your script tag above in the page that does the ajax call, then when you load the link below into the page with ajax, it should be lightbox functional, unless lightbox itself requires that you run it's initiazation function again so that it knows about the link. <a href="img/galeria/2.jpg" rel="lightbox" title="untitled. mixed media on canvas. 100 x 180 x 12 cm. 2006."><img src="img/galeria/thumb_2.jpg" alt="" width="66" height="90" border="0" /></a> 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.