how to get xmlhttpRequest-result global ?

in Script development
Subscribe to how to get xmlhttpRequest-result global ? 8 posts, 3 voices

Vivre Scriptwright

after a hole day I finally achived to grab information via GM_xmlhttpRequest ...

This information is a piece of string placed into a variable.
eg. var found = "whatsoever"

Now inside of the whole GM_xmlhttpRequest - routine I can change/use... it. BUT I need it in another part of the script outside of this routine.
Even if I made 'found' global from the scripts beginning it will not be affected by the response result and stay an independent variable of it's own.

How can I make (export/transfer) a result from an xmlhttpRequest be available in the later script?

greets ~ V

smk Scriptwright

var r='';

function test(){

method: "GET",
url: "",
headers: {
"User-Agent": "Mozilla/5.0",
"Accept": "text/xml"
onload: function(e) {

works perfectly
and use GOOGLE next time to save you (and us) a day
search for other errors in your script

Vivre Scriptwright

Thanks for your quick reply - and sorry that it took you 2 minutes time.

I have been searching many scripts and references, also the guide etc. but I won't ask g00gle.

Ok - trying your example (with a different url) and appending
alert('r.: '+r);
behind your example: r stays just as empty as my variable.

smk Scriptwright

that's because GM_xmlhttpRequest is asynchronous
onload is executed after your alert
to see this try putting an alert in onload

Vivre Scriptwright

Yes - I wrote it above - I have no problem INSIDE GM_xmlhttpRequest but I need the result in another part of the script.

smk Scriptwright

use callbacks, events, things like that

Vivre Scriptwright

Great - a completely different topic to work through - so some more days until that (incl. all ref-links ect.) again is grasped. And then search for the hidden connection to xmlhttpRequest ....

That's what I'm doing all the time - and when I'm so stuck like now I dare to ask this forum.
I know it's more succsessfull to request complete scripts .... it's so frustrating.


later: Got it - explanation follows after break

SBscripts Scriptwright

If you want to make a variable global from inside a function, just use

function foo(){