Hello all

It's my first attempt to write a GM script and I start to become
crazy !!
I written the following code (I removed useless code):
---- Begin code ----
var fgsServer = "http://192.168.56.101/fgs/gmAjx.php";;

/* We attach an event listener to the body tag and trigger the
function 'message' each time that an element is inserted in the page
*/
var el = document.body;
el.addEventListener('DOMNodeInserted', message, false);

/* Main function */
function message(event) {
/* first we capture the id of the new inserted element (the one who
created the event) */
        var objId = event.target.id;
        /* if it exist then we can do something with it (we have no interest
on elements without id) */
        if (objId) {
                /* then we check if it's a windows, if it's have a 'title' 
element
*/
                var em = document.getElementById(objId+'title');
                if (em) {
                        alert("1");
                        toto();
                }
        }
}

function toto() {
        alert('toto');
GM_xmlhttpRequest({method: "POST",url: fgsServer,data:
"username=johndoe&password=xyz123",headers: {"Content-Type":
"application/x-www-form-urlencoded"},onload: function(response)
{alert(response.responseText);}});
}
----- End code -----

As written in the comments, I attach an event listener to the body tag
of a page. Each time a node is added to the page I call a function
"message()".
At one moment, this function try to sent some data to a remote php
script.
the alert("1") is displayed
the alert("toto") is displayed
but the GM_xmlhttpRequest never sent anything (traced with "Tamper
Data" extension)

However, if outside the function message() , I call the function
toto(), everything work find ! I see the Ajax request sent in Tamper,
my php script receive the data, reply and the response is displayed

So it seems that I can't use GM_xmlhttpRequest in a function trigger
by an event !!
Can you confirm ?
Or I have made something wrong ?

ericc

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to