0

My AJAX returns a block of code in JS. I have tried converting this to a function that is then called AFTER the AJAX request returns, but for some reason in my FireBug console I am being told the function doesn't exist. The AJAX returns a block of JS and sets it into a div called "content". However, these functions do not appear to register and aren't called. Even when they aren't functions and are standard statements that would otherwise execute they still do nothing!

Absolutely everything is in place and works perfectly except this final part where the returned JS code doesn't execute.

Clearly, the JS code block isn't inside the <head> element, however, I am sure I've managed to execute JS code outside of that element before.

Is there anything I am doing majorly wrong, and is there a work around? The JavaScript code block edits the localStorage and so I cannot use another language instead, the code block is also generated using PHP and is dynamic as it changes variables depending on user input.

user2195574
  • 57
  • 1
  • 8
  • 2
    Adding ` – Pointy Jun 17 '14 at 19:42
  • I have since found this and edited the code as such, the reponse from AJAX still places it inside the content div. Following this I `eval(a.innerHTML)` (where 'a' is obtained through `var a = document.getElementById('content');` I am still left with nothing happening, oddly enough, out of curiosity I attempted to `eval()` the `xhr.responseText` with no success. I have an alert at the start of the code block just to be alerted when it IS run. – user2195574 Jun 17 '14 at 19:49

1 Answers1

0

https://stackoverflow.com/a/10073403/2195574

Found my answer here! Simply added an id to the script and executed it that way with eval(). Looked at the default drop downs in DW and id wasn't among them otherwise I'd have tried this prior to posting!

Community
  • 1
  • 1
user2195574
  • 57
  • 1
  • 8