Skip to content Skip to sidebar Skip to footer

Greasemonkey: Gm_xmlhttprequest Return Value To Calling Function

ive been messing round with this for hours and im pulling my hair out at it. How do I return var a from myFunction to allow it to be set as var b which and then display the value o

Solution 1:

You can't return a like that because GM_xmlhttpRequest operates asynchronously.

The onload function will fire long after myFunction has returned. Anything that you want to do with a will have to be done from functions called within the onload function.

Greasemonkey just added support for synchronous mode, starting with version 0.9.9. If you must, you can download the prerelease of version 0.9.10, here.

However, you would be smart to learn to handle this kind of thing asynchronously. You will get a faster, more responsive UI instead of "hangs" and "freezes". It's a good concept to grok for all manner of real-life programming situations.

Post a Comment for "Greasemonkey: Gm_xmlhttprequest Return Value To Calling Function"