
Quote from roccocogliano on December 15, 2023, 1:10 pmHi @luishp,I need your precious help, if possibleIs it possible to pass parameters to the 'success Subroutine'?I have a series of calls to neoAjaxLoad in a loop to read a series of files within a server.I'll explain why: I would like to identify each individual call so as to assign the result of each individual call to a composite variable.Something like that:.[jsonTab] is a jSon object LoopObject [p] [jsonTab] SetVar [Name] [jsonTab([p]).SIGLA] SetVar [URL] [jsonTab([p]).URL] neoAjaxLoad "[URL].txt" "text" "loadValues_OK [Name]" "loadValues_KO [Name]" EndLoopand in the 'loadValues_OK' function (with data read in the variable [data]) assign the result to a composite variable (e.g. with setcompvar [values_[param]] [data]); and in the 'loadValues_KO' function assign the error to a composite variable (e.g. with setcompvar [values_[param]] "error")
Or is there an alternative solution that I can't find at the moment?Thanks in advanceRocco
.[jsonTab] is a jSon object
LoopObject [p] [jsonTab]
SetVar [Name] [jsonTab([p]).SIGLA]
SetVar [URL] [jsonTab([p]).URL]
neoAjaxLoad "[URL].txt" "text" "loadValues_OK [Name]" "loadValues_KO [Name]"
EndLoop
and in the 'loadValues_OK' function (with data read in the variable [data]) assign the result to a composite variable (e.g. with setcompvar [values_[param]] [data]); and in the 'loadValues_KO' function assign the error to a composite variable (e.g. with setcompvar [values_[param]] "error")

Quote from luishp on December 15, 2023, 1:40 pm@roccocogliano I have just modified the plugin so you can do what you want using a new command: neoAjaxLoad2
Please download and install the attached plugin. I have also included the plugin source file just in case you need to do additional changes.
Note that the parameter will be sent as a second argument to the subroutine (first one is the retrieved data).
Let me know if you need anything else.Regards.
@roccocogliano I have just modified the plugin so you can do what you want using a new command: neoAjaxLoad2
Please download and install the attached plugin. I have also included the plugin source file just in case you need to do additional changes.
Note that the parameter will be sent as a second argument to the subroutine (first one is the retrieved data).
Let me know if you need anything else.
Regards.
Uploaded files:
Quote from roccocogliano on December 15, 2023, 1:45 pmWow what speed!
Thanks so much @luisp, I'll try it right away
Rocco
Wow what speed!
Thanks so much @luisp, I'll try it right away
Rocco

Quote from roccocogliano on December 15, 2023, 4:25 pm@luishp
I can't use the parameter, it's always undefined.
for example,
neoAjaxLoad2 "[URL]" "text" "load_OK" "load_KO" "[name]"
then, adding [p] parameter in load_OK and using it, its value is 'undefined'
I can't use the parameter, it's always undefined.
for example,
neoAjaxLoad2 "[URL]" "text" "load_OK" "load_KO" "[name]"
then, adding [p] parameter in load_OK and using it, its value is 'undefined'

Quote from roccocogliano on December 15, 2023, 5:44 pmok, there was a small error in the neoAjax2 function. Fixed the error and everything works.
here is the correct code for neoAjax2 in the plugin:function neoAjaxLoad2(theUrl,theDataType,successSubroutine,errorSubroutine,param){ $.ajax({ url: theUrl, dataType: theDataType, success: function(data){ if(successSubroutine){ successSubroutine(data,param); } }, error: function(data){ if(errorSubroutine){ errorSubroutine(data,param); } } }); }
ok, there was a small error in the neoAjax2 function. Fixed the error and everything works.
here is the correct code for neoAjax2 in the plugin:
function neoAjaxLoad2(theUrl,theDataType,successSubroutine,errorSubroutine,param){
$.ajax({
url: theUrl,
dataType: theDataType,
success: function(data){
if(successSubroutine){
successSubroutine(data,param);
}
},
error: function(data){
if(errorSubroutine){
errorSubroutine(data,param);
}
}
});
}