As indicated here:
How can I return a value from GM_xmlhttprequest?
I have a script that is asynchronous. I would like to pass a value INTO this function so that when the onload function is called I can use it to display in the web page.
The challenge I'm having is that this value will change each time I pass it into the function.
So, for instance if I passed in 'abc', 'def', 'xyz'.
I would end up with
xyz
xyz
xyz
instead of
abc
def
xyz
So, my question is, how would I pass a value into this function so that each call of the function knows what to display when it's done?
You are looking for a closure:-
This will alert "abc", "def" and "ghi" after each outstanding request completes.