[Greasemonkey] Returning values on xmlhttpRequest

Matthias Bauer ml-greasemonkey-42imk83y at moeffju.net
Thu Jun 16 23:04:47 EDT 2005


On 15.06.2005 16:47 Premshree Pillai wrote:

> 	window.lj = function() {
[...]
> 		GM_xmlhttpRequest({
> 			onreadystatechange:function(details) {
[...]
> 					return titles;
> 	var titles = lj();
> 	alert(titles); // undefined!

You're returning from an anonymous function, which basically runs in a
void. You would need to return from the lj() function, but since the
GM_xmlhttprequest is asynchronous, there's no way to get the value back
into that function. What you'll need to do is use a callback function
that sets a value and/or triggers further processing.

-Matt


More information about the Greasemonkey mailing list