anyone can suggest me how to call parse without use parseFunc as argument in aj.call ? I think it's a bad idea "override" prototype.parse and then pass as argument, why cant use the aj.parse directly? ecma5 because it works in Iternet Explorer compatibility mode on (old IE version) Thanks
function AjaxFactory(){
}
AjaxFactory.prototype.async = false;
AjaxFactory.prototype.method = "GET";
AjaxFactory.prototype.parse = function (result){
return result;
}
AjaxFactory.prototype.call = function (callActionUrl, data, parseFunc){
jQuery.ajax({
url: callActionUrl,
method: this.method,
data: data,
success: function (result) {
return parseFunc.call(this,result);
},
async: this.async
});
}
/*
* es:*/
var myParser = function (result){
return "my parser of " + result;
}
var url = "";
var aj = new AjaxFactory();
aj.parse = myParser;
aj.async =false;
aj.method = "GET";
alert(aj.call("url",{}, aj.parse));
*add 08 Dec 2020
I have also this question: the return value does not return when i do alert(aj.call) so i change as below. But i suppose: does it working when async is true? Maybe 'return outreturn' can be executed before that 'success' was called..can you suggest me? Maybe can i use the result directly in the parse function..right? Thanks
AjaxFactory.prototype.call = function (callActionUrl, data, parseFunc){
var outreturn;
jQuery.ajax({
url: callActionUrl,
method: this.method,
data: data,
success: function (result) {
outreturn =parseFunc.call(this,result);
},
async: this.async
});
return outreturn; <-- this can be wrong when async true
}