Skip to content Skip to sidebar Skip to footer

Why Isn't This Javascript Executed?

I was actually not going to, and am afraid of asking such a silly question, but i have completely no clue what is going wrong here. My JavaScript function ahah(url, target) { do

Solution 1:

In your 'ahah' function, should

document.getElementById(container).innerHTML = ' Fetching data...';

Be

document.getElementById(target).innerHTML = ' Fetching data...';

?

Solution 2:

When using innerHTML to re-define some part of the page, the <script> tags that are contained in the HTML portion you are inserting into the page are not executed -- that's just the way it is.

You'll have to use some other way to add you data to the page ; like DOM manipulation, for instance, I suppose.

There are some elements that might help under this question : Can scripts be inserted with innerHTML?

Solution 3:

Changed the function ahah() slightly:

functionahah(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...'; // change container to targetif (window.XMLHttpRequest) {
    req = newXMLHttpRequest();
  } elseif (window.ActiveXObject) {
    req = newActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send(null); // sending a GET request - do not send any data.
  }
}

Check if the variable "req" is properly assigned and the AJAX request is indeed sent.

Post a Comment for "Why Isn't This Javascript Executed?"