Great thank you, you were right - executing everything in onSuccess() solved my issue ! :)
I'm working on integrating JavaScript InfoVis Toolkit <http://thejit.org/>with XWiki - at least some graphs. So now I can successfully display an hyperbolic tree in a wiki page with json data provided from another page :) My primary intent was to display parent-child relation-ships using a SpaceTree, a bit like the MindMap snippet. Thanks again for your help Sergiu, Jeremie 2010/3/2 Jeremie BOUSQUET <[email protected]> > Yes, the purpose was to use json var after the Ajax.Request() block ... > Understood, I will make a function of the rest of the code and pass in the > onSuccess, thanks. > > I tried the asynchronous:false with no different result, but I would have > to test again to be sure. > > Thx, > Jeremie > > 2010/3/2 Sergiu Dumitriu <[email protected]> > >> On 03/02/2010 01:15 AM, Jeremie BOUSQUET wrote: >> > Hello, >> > >> > This is for something I'm trying to develop ... And I'm not sure it has >> > something to do with XWiki, but who knows ? >> > >> > In a page I call a particular init() function like this : >> > >> > Event.observe(window, "load", init); >> > >> > This init() aims at loading some JSON data from another page using Ajax. >> I >> > was inspired by the livetable.js here :-) >> > >> > var json = "" >> > var ajx=new Ajax.Request( " >> > >> http://localhost:8081/xwiki/bin/view/Dev/JSONProvider?xpage=plain&outputSyntax=plain >> ", >> > >> > {method:"get", onSuccess:function(transport) { json = >> > eval("("+transport.responseText+")"); } >> > } >> > ) >> >> Wait, do you use json here, after the new Ajax.Request? You can't do >> that. You should put the code using json inside the onSuccess handler. >> >> Alternatively, you can add >> asynchronous: false, >> to the list of parameters to make the call synchronous, which means that >> the new Ajax.Request line will block until the response arrives. But >> this is bad for several reasons: in most of the current browsers it >> blocks the entire browser until the response arrives, so if the server >> is slow to respond, you'll lock the user outside the browser; the method >> might fail, so onSuccess will not be called, and json will still have >> the wrong value. >> >> > This Javascript is in a .js file along with other resources on the >> server >> > filesystem. It is loaded with $xwiki.jsfx.use(...) . >> > When I debug step by step using Firebug, everything is fine, "json" >> variable >> > contains what I expect. >> > But when I'm not debugging and refresh the page, "json" variable is >> empty >> > ... (breakpointing AFTER ajax call shows it). Though I can see in >> Firebug >> > that my Ajax http request finished with a 200 OK code. >> > >> > Do you think it might be linked to the fact this method is called on >> page >> > load ? I can't see how it's different than other ajax calls in xwiki ... >> > >> >> >> -- >> Sergiu Dumitriu >> http://purl.org/net/sergiu/ >> _______________________________________________ >> users mailing list >> [email protected] >> http://lists.xwiki.org/mailman/listinfo/users >> > > _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
