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&outputSynt...",
You should use what Prototype already offers: - set the proper MIME type for the response from velocity, with $response.setContentType('application/json') - write well formed JSON (also include the ( and ) that you append before the eval in your current code - use transport.responseJSON to read the already parsed JSON data
{method:"get", onSuccess:function(transport) { json = eval("("+transport.responseText+")"); } } )
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.
Can you also check the content of the response, to see if it's well formed JSON? If you also set the right MIME type, then Firebug should provide a tab with the JSON data of the response (depends on the actual Firebug version).
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/