views:

140

answers:

1

You have to pass the args variable to the anonymous function, but the anonymous function does not visibly need the args variable, so you have to memorize when Dojo needs the args variable, but the Dojo help page doesn't say! So, when does Dojo need the args variable?

var init = function(){
var contentNode = dojo.byId("content");
dojo.xhrGet({
    url: "js/sample.txt",
    handleAs: "text",
    load: function(data,args){
 // fade out the node we're modifying
 dojo.fadeOut({
     node: contentNode,
     onEnd: function(){
  // set the data, fade it back in
  contentNode.innerHTML = data; 
  dojo.fadeIn({ node: contentNode }).play();    
     }
 }).play();
    },
    // if any error occurs, it goes here:
    error: function(error,args){
 console.warn("error!",error);
    }
});
}; 
dojo.addOnLoad(init);
+2  A: 

To clarify: you are referring to the "args" argument you have in your code sample that is part of the function definitions for the "load} and "error" callbacks:

You only need the args variable if you need to use it. Dojo itself does not need it. Normally you should not need it. The first argument should be the result you are looking for.

However, if you need to access the raw XMLHttpRequest object, then args.xhr will hold it.

Similarly, if you want access to the original object you passed to dojo.xhrGet (because you stored some sort of state on it), you can get it at args.args (for this reason, I normally name that argument ioArgs, so it would then be ioArgs.args).

jrburke