Jump to content
Vhaerun

Intrebare javascript

Recommended Posts

Posted

Atat GM_xmlhttpRequest cat si xmlhttpRequest sunt asincrone . Cu greasemonkey voiam sa extrag niste date dintr-un site dupa o expresie xpath , dar din cauza faptului ca request-ul e asincron , codul meu nu se executa cum ar fi firesc .

codul meu ar fi urmatorul :


function gGet(link,func,elements) {

GM_xmlhttpRequest({
method: 'GET',
url: link,
headers: {
'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
'Accept': 'application/atom+xml,application/xml,text/xml',
},
onload: function(responseDetails) {
func(responseDetails.responseText);
}
});

}

var elements = new Array();
gGet("some.site",function(content) {
parsarea elementelor si adaugarea lor in array
...
elements.push(parsedElement);
},elements);
...
procesarea elementelor array-ului

problema ar fi ca scriptul incepe sa imi proceseze elementele array-ului pana nu termina de executat GM_xmlhttpRequest , which is not good .

Ceva work-around-uri sau sfaturi cum pot sa fac request-ul sa fie sincron ?

Posted

Cred ca in spate , greasemonkey foloseste XmlHTTPRequest , dar nu sunt sigur . Asa ca sa mearga cum am eu nevoie , ar trebui sa dezactivez restrictiile cross-domain impuse de firefox , which doesn't seem like a good thing :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...