Jump to content

http request don't keep the javascripts working


alapimba

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?  ???

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.