Vhaerun Posted August 1, 2008 Report Share Posted August 1, 2008 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-uluiproblema 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 ? Quote Link to comment Share on other sites More sharing options...
Grunt Posted August 1, 2008 Report Share Posted August 1, 2008 Daca obj ar fi de tip XmlHttpRequest, atunci merge ceva de genul:obj.onreadystatechange=function() {if (obj.readyState==4) { // do stuff here }} Quote Link to comment Share on other sites More sharing options...
Vhaerun Posted August 1, 2008 Author Report Share Posted August 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
dblackshell Posted October 23, 2008 Report Share Posted October 23, 2008 cum sa integrezi readyState in scriptu tau -> GM_xmlhttpRequest [Dive Into Greasemonkey] Quote Link to comment Share on other sites More sharing options...