[Greasemonkey] GM_xmlHttpRequest question
Tom Emerson
osnut at pacbell.net
Sat Jul 29 11:53:11 EDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Anthony Lieuallen wrote:
> On 7/28/2006 4:20 PM, Jossie Mann wrote:
>> ... My problem is, how can I store the association between the html
>> tag and the xmlHttpRequest so that when the xmlHttpRequest returns
>> back to the page I know which html tag triggered it.
>
> Your answer is closures:
> http://en.wikipedia.org/wiki/Closure_(computer_science)
> http://jibbering.com/faq/faq_notes/closures.html
This is why I asked for someone knowledgeable in javascript to "do the
work for me" -- apparently I did this "wrong", but I had a similar
problem that I solved by creating an array of the original anchor
elements, indexed by the "page id" that was common between the source
request and the resulting page request, and then in the "onload" event
of GM_xmlhttpRequest I could recover that same index value to find the
original anchor tag in the array.
You can see the results of my work at
http://userscripts.org/scripts/source/4364.user.js
> In pseudocode:
>
> for (elements) {
> function() {
> el=elements[i];
> xhr_start(callback=xhr_call);
> }
> }
>
> function xhr_call() {
> el.innerHTML=response.responseText;
> }
For the javascript/greasemonkey pros out there -- would someone be so
kind as to make suggestions / rewrite my script to make use of said
"closures" (in a way that I might actually grok it) -- obviously what I
have works, but from reading the jibbering page, what I'm doing may be
causing more harm than good (I think) or possibly doing this a "more
correct way" would be faster (not that this is "slow", but there are
times or cases where I'd like it to move along a little faster...)
- --
Top o' the Blog: It's good to be the King...
http://osnut.homelinux.net/mtblog/ya_index.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEy6CHV/YHUqq2SwsRAjQjAJwMmBBoNPuVGawPKHAAH3UjhBc1iwCeOJhs
fjz1aVpgJHDC+hF1Ou+g+/Q=
=7042
-----END PGP SIGNATURE-----
More information about the Greasemonkey
mailing list