I previously used Prototype.js for ajax requests, and now I wanted to try using Dojo.
My code of line with Prototype.js
var pars = 'watch_video=' + vid;
var myAjax = new Ajax.Updater('flash_player', 'post/', {method: 'post', parameters: pars });
<em>
where 'flash_player' is ID of a DIV, 'post/' is the URL, and pars are the parameters.
In dojo, I have to make the request in following format:
url: 'post/',
load: ID,
error: ajaxError,
content: {watch_video: vid }
});
function ID(data, ioArgs)
{
setHtml('flash_player', data);
}
I would like to know how can I send ID of the DIV to the function? I want to have one central function which will take in data and ID of a DIV, and it will put the data into it. I don't want to create function for each ajax request.
Further more, is it possible to create a variable pars with the paramters I want to send, and just have that variable name after content:
Thanks for reading my question.

You can use an anonymous
You can use an anonymous function to create a closure that has access to the div's ID:
dojo.xhrPost({
url: 'post/',
content: {watch_video: vid},
load: function(data, ioArgs){
setHtml(divId, data);
},
error: ajaxError
});
}
not that it is a documented
not that it is a documented or support feature, but by nature anything you stash in the xhr object hash is passed to ioArgs.args:
id:"foobar",
url:"foo.php",
load: function(data, ioArgs){
// ioArgs.args.id == "foobar"
}
});
From:
http://dojocampus.org/content/2008/03/14/functional-ajax-with-dojo/