Login Register

dynamic execution of the XHR response content

Hello,

I'm evalutaing Dojo by recreating an application previously built with other frameworks. Liking it so far and it's a lot lighter! But just encounter my first road block was hoping someone could help me solve...

Does Dojo provide a means for dynamically executing an XHR response content. In other words parse the xhr response for script tags and execute this javascript?

We've used the following solution (a plugin for YUI) in the past if this helps you understand our requirement.

http://www.bubbling-library.com/eng/api/docs/plugins/dispatcher

Many thanks in advanced!

Cheers,
Grant

dojox.layout.ContentPane supports script execution

n/t

I believe the

I believe the xhrPost:handleAs property can be set to "javascript" so the response is then eval'd by dojo. But I'm really new to this so cant be sure and of course havent tried it out! Anyway HTH

In case you want to load and

In case you want to load and display new html content, that holds scripts inside: dojox.layout.ContentPane is what you are looking for. But if you just want to execute js recieved via xhr: dojo.eval(xhrAnswer).

does ContentPane run inline

does ContentPane run inline scripts in addition to referenced ones?

e.g.

< script >
function runThis() { ... }
< /script >

< script type="text/javascript" src="morecode.js" / >

It does

but make sure, you use dojox.layout.ContentPane and not dijit.layout.ContentPane

Thanks - I was clarifying

Thanks - I was clarifying because I was using the dijit.layout.ContentPane...

I've now got a working example combined with Dialog - but I'm not sure this is the best way to go about this.. It would be nice to just have a executeScripts flag on the dijit.Dialog... oh well this works, just seems like a lot of code to achieve something simple? Perhaps someone more familiar with Dojo can suggest a simpler solution...

function loadContainer(url) {

        var dialogDiv = document.createElement("div");
        document.body.appendChild(dialogDiv);
        dialogDiv.setAttribute("id","input-dialog");

        dialogDiv.innerHTML = "<div>loading</div>";
        dialogDiv.firstChild.setAttribute("id","dialog-widget-loading");

        var dialog = new dijit.Dialog( {
                draggable: false,
                onCancel: function() {
                    dialog.destroy();
                }
            }, dialogDiv );

        var contentDiv = document.createElement("div");
        document.body.appendChild(contentDiv);
        contentDiv.setAttribute("id","dialog-content");

        var contentPane = new dojox.layout.ContentPane( {
                href: url
                renderStyles: true,
                executeScripts: true,
                onDownloadStart: function() {
                    dialog.show();
                },
                onDownloadError: function() {
                    dijit.byId('input-dialog').setContent(this.errorMessage);
                    contentPane.destroy();
                },
                onLoad: function() {
                    dijit.byId('input-dialog').setContent(dojo.byId("dialog-content").innerHTML);
                    contentPane.destroy();
                }
            }, contentDiv );
        contentPane.startup();
    }