[Dojo-interest] my way of running scripts with dojo.io.bind
jbowman
forum-dojo-interest at opensymphony.com
Thu Apr 6 21:02:38 MDT 2006
like a lot of people, I've been wanting to figure out a way to include javascript in my dojo.io.bind calls. Unfortunately, I'm a php/perl person, not a javascript developer. What I eventually did was find a way to basically get what I wanted done.
dojo.byId works on getting elements after they are set with a dojo.io.bind call. And you can use dojo.io.bind using javascript too. So basically I've seperated my stuff into two calls. I basically do something like
dojo.io.bind({
url: "script.php",
mimetype: text/html,
method: POST,
handler: function( type, data, evt ){
var output = dojo.byId("outputDiv");
output.innerHTML = data;
/* javascript to manipulate the new DOM here */
}
});
Now you can also have the extra javascript pull in another file, like.
dojo.io.bind({
url: "script.php",
mimetype: "text/html",
method: POST,
handler: function( type, data, evt ){
var output = dojo.byId("outputDiv");
output.innerHTML = data;
dojo.io.bind({
url: "script.js",
mimetype: "text/javascript"
handler: function( type, data, evt){
eval(data);
}
});
}
});
I haven't done the second part yet, because I'm still working on the backend scripts to create the javascript. I have dynamic variables that have to placed, but you can call a dojo.io.bind to run a php (or whatever) script, and as long as it returns valid javascript, you can use the text/javascript mimetype and eval it.
The last thing I'm going to have to figure out is if publishing events works this way, on top of the original javascript loaded on the page.
For a lot of you this may be something like... duh!. But I doubt I'm not the only one who hasn't done much with javascript in the past, who has found dojo, and been like.. whoa cool!
Thanks again to guys who are developing this. It really is an invaluable tool for web design.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=25018&messageID=48843#48843
More information about the Dojo-interest
mailing list