[Greasemonkey] Check COinS against OpenURL Resolver via
GM_xmlhttpRequest
Aaron Boodman
zboogs at gmail.com
Thu Dec 29 10:59:24 EST 2005
This is a common problem with async javascript.
You are in a loop, shooting off a request for each item. Each request
does fire, but by the time any of them return the loop has completed.
The variables used inside the loop still exist, but they have the
values they had on the last iteration.
So in this case, when each of the requests returns /e/ has the value
it had on the last iteration of the loop.
The way to fix this is to call an actual function in the loop, passing
it arguments. In contrast to the local variables in a loop, each set
of parameters to a function call is separate. So like this:
for (var i = 0; i < whatever; i++) {
doSomething(elms[i]);
}
function doSomething(elm) {
GM_xmlhttprequest({
onload: function() {
// you can use elm here
}
});
}
- a
More information about the Greasemonkey
mailing list