neoAjaxLoad and successSubroutine, errorSubroutine callback - Forum

Forum Navigation
You need to log in to create posts and topics.

neoAjaxLoad and successSubroutine, errorSubroutine callback

Hi @luishp,I need your precious help, if possible
Is 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]"
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")

Or is there an alternative solution that I can't find at the moment?
Thanks in advance
Rocco

 

@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:
  • You need to login to have access to uploads.
roccocogliano has reacted to this post.
roccocogliano

Wow what speed!

Thanks so much @luisp, I'll try it right away

 

Rocco

@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'

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);
          }
        }
  });
}

 

luishp has reacted to this post.
luishp