In an Ajax request with JQuery I need to place the execution of a function in the success property. But this function is passed as an argument to the function in which the Ajax request is made. That is, within the Ajax request I can only indicate the execution of that function through the string parameter that corresponds to its name. The problem I have is that if I put the name of the parameter followed by "();" it is not executed as a function. Thus:
success: function (devolucion) {
callback();
},
callback is the name of the parameter that is received in the function in which the request is made. As my wish is that this function is executed, I write the name of the parameter adding " (); ", which surely is not right. I would need to know how I would have to write that function name through the parameter that contains it so that it can be executed. It is also something that cannot be done, but I launch the query because sometimes there are solutions for everything.
Greetings and thanks
success
Ajax will auto-invoke at the end of the request, it will execute the function you assign to it, but itcallback()
is out of its scope. Assign your function WITHOUT calling it. Your callback function, if needed, will store the result of the request.I leave you an example