I currently have a code that is able to run and collect data using an AJAX library. My goal is to allow users to add their own functions to the library and execute them, similar to $.get
. It may be a bit difficult to fully explain what I am trying to achieve.
FOR EXAMPLE:
_$.ajax({
url:"url",
cache:false,
done:function(data){
console.log(data);
}
});
My challenge lies in ensuring that the variable 'data' actually refers to ajax.response
, which essentially represents the collection of XMLHttpRequest.responseText;
I attempted to implement the following within my code:
var ajax = {
response:null,
fnDone:null,
done:function(fn){
return ajax.done.call(fn);
},
init:function(){
ajax.process();
},
process:function(){
ajax.done(ajax.fnDone);
},
ajax:function(opts){
ajax.fnDone = opts.done;
}
};
However, it seems like this approach is not yielding the desired results. Could someone provide a clearer explanation on the arguments being passed to the call?
LATEST DEVELOPMENT:
I am seeking guidance on how to set arguments as predefined variables.
FOR INSTANCE:
_$.ajax({
url:"url",
cache:false
}).done(
function(
data){ console.log(data); });
Here, the argument name 'data', or any preferred name, should already be established as referring to ajax.response
.