• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Running Javascript embedded in div after AJAX call

Drakkon

Diamond Member
I'm trying to make an AJAX call load a page into that page - and within that page is a embedded Javascript call so that way those function get called after the AJAX loads. However I've had no luck as of yet as it doesn't seem to parse the javascript that is loaded. I can see in firebug the content gets loaded into the div just the javascript does not process. Is it possible to embed content like this?
---------------------------------
Current page:
(div id="content")(/div)
--------------------------------
Javascript:
AJAX.call(alert.php);
AJAX.onstatuschange = function (responseText) {
#('content').innerHTML = responseText;
}
--------------------------
PHP page (call alert.php)
(script)alert('hello')(/script)

-----------------------------------
 
I have done this before. I don't know if this would be the "correct" way to do it, but it works.

Try something like this:

Current page:
(div id="content")(/div)
--------------------------------
Javascript:
When you get the response text back... to run the javascript you can use:
eval(responseText);
--------------------------
PHP page (call alert.php)
echo "alert('hello')";
 
In order to do something like this, you'd need to get the response, then parse the response to get out the scripts. If just plain <script> and </script> are dependably there, can probably just use a pair of splits. If not, you'll need some kind of marker.

Then, you can eval the javascript, or create a new <script> element and append it to the current page.
 
Back
Top