Reputation: 1297
I'm writing a single page website using dojo. Tutorials describe how to use dojo/request for making ajax requests. I can simply make request, receive html content and insert it into a content panel (div element). This is also demonstrated in the samples.
When I start to load real content with some desired functionality, I need to also add a script element to the content which is requested by an ajax call. The problem is that the script received with ajax content is not executed.
I tried using contentNode.innerHTML = data;
and also domConstruct.place(data, contentNode, "only");
In both cases content is shown but the scripts inside the content is not executed.
As I understand there's also a dijit.layout.ContentPane
which is more suitable for loading content on design time, not runtime.
I cannot execute the script before the content is loaded, because in every page there are some elements which I need to process, and they are simple not available when the main page is loaded. For example, I need to change form submission behavior.
So what can I do to make the loaded script executed?
Upvotes: 0
Views: 841
Reputation: 8113
There is a dojox.layout.ContentPane
that provides the ability to execute scripts from the loaded content.
See the official documentation here. It excplicitly addresses your use case
If you need to execute JavaScript inside your content panes, use dojox/layout/ContentPane instead of dijit/layout/ContentPane and set executeScripts=”true”. Actually executeScripts defaults to “true” but might be a visual cue down the road as to why you are using dojox/layout/ContentPane.
Upvotes: 1