No, i am not aware of the closures concept,
i needed to use ajax in the application, and had a bit of idea about it, so i thought probably i will learn more about it as and when i progress along and encounter some issues..
Please direct me to a nice link explaining the closures..
If you use a library such as jQuery for your Ajax (highly recommended -- there are just too many nuances to keep track of to write it "by hand"), things are really easy. Consider:
How easy is that? Compare that to the number of lines of code you are now writing to make an Ajax request.
The body of the callback function has access to the variable xyz because it is part of the closure created when the function is defined inline in this way.
Essentially a closure is the combination of a function instance and all the variables that are in-scope when the function is declared. Even if the block in which the function and variables are declared goes out of scope, which would usually result in the variables being reclaimed, the variables are retained and can be used when the function executes.
I am just starting to get a bit embarrassed here, because i dont really know what jquery is and how to use it and what are its advantages...
and i am inclined to use normal ajax call just to save time(i was just trying to write my own application and sort of lagging behind the timeframe which i had set.. )
Further, the problem here is this.
I am having multiple forms in the page and at one time only one is submitted and makes an ajax call, while clicking the button to make the ajax call, it passes some parameters, and one of the parameters is the method it should execute after the call returns, so my code was looking like this..
so that each form wants a different callback to execute, whose name it passes as a parameter to the function making the ajax call.
so that writing
will not work as i have to call a different method for each form.
I will probably need to avoid the generalization of the passing the method name as parameter and try to make it work.
With regards to your code, how is postAjax() being called? If you pass a function reference (not a function call) as the first parameter, the callback should be registered correctly.