Re: [xwiki-users] Strange ajax + json issue
Hi Jeremie, Jeremie BOUSQUET wrote: Hello thx Sergiu, I changed to json content-type, and responseJSON as you proposed. I checked that my GET request is 200 OK, and in the response the JSON tab in Firebug shows well formed JSON. But still my json variable is empty at execution time ! By the way if I breakpoint on or before the Ajax.Request() and step over the code, the json variable gets properly initiated and executed. Where it's used afterwards, it's perfectly well formed. I also added url parameters as 'parameters' of Ajax.Request instead of directly in the url but no change. Could it be a problem in the way I pass my json variable ? Declared outside of Ajax.Request(...) ? It must be something really stupid but I just don't understand ... Assign a default value to your json variable before making the request then invoke the Firebug debugger in your onSuccess handler by simply writing: debugger; before the response assignation. Refresh the page and check if your json variable has the default value before being assigned with the JSON response and if the response if evaluated correctly. If all this is fine then maybe your json variable is affected elsewhere. Hope this helps, Marius Jeremie 2010/3/2 Sergiu Dumitriu ser...@xwiki.com 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=plainoutputSyntax=plain , 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/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
Marius Dumitru Florea wrote: Hi Jeremie, Jeremie BOUSQUET wrote: Hello thx Sergiu, I changed to json content-type, and responseJSON as you proposed. I checked that my GET request is 200 OK, and in the response the JSON tab in Firebug shows well formed JSON. But still my json variable is empty at execution time ! By the way if I breakpoint on or before the Ajax.Request() and step over the code, the json variable gets properly initiated and executed. Where it's used afterwards, it's perfectly well formed. I also added url parameters as 'parameters' of Ajax.Request instead of directly in the url but no change. Could it be a problem in the way I pass my json variable ? Declared outside of Ajax.Request(...) ? It must be something really stupid but I just don't understand ... Assign a default value to your json variable before making the request then invoke the Firebug debugger in your onSuccess handler by simply writing: debugger; before the response assignation. Refresh the page and check if your json variable has the default value before being assigned with the JSON response and if the response if evaluated correctly. If all this is fine then maybe your json variable is affected elsewhere. As you know, A in AJAX comes from Asynchronous so don't use your json variable before the response is received, i.e. before the onSuccess handler is called. Hope this helps, Marius Jeremie 2010/3/2 Sergiu Dumitriu ser...@xwiki.com 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=plainoutputSyntax=plain , 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/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
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=plainoutputSyntax=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 users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
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 ser...@xwiki.com 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=plainoutputSyntax=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 users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
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 jeremie.bousq...@gmail.com 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 ser...@xwiki.com 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=plainoutputSyntax=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 users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
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=plainoutputSyntax=plain;, 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/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
Hello thx Sergiu, I changed to json content-type, and responseJSON as you proposed. I checked that my GET request is 200 OK, and in the response the JSON tab in Firebug shows well formed JSON. But still my json variable is empty at execution time ! By the way if I breakpoint on or before the Ajax.Request() and step over the code, the json variable gets properly initiated and executed. Where it's used afterwards, it's perfectly well formed. I also added url parameters as 'parameters' of Ajax.Request instead of directly in the url but no change. Could it be a problem in the way I pass my json variable ? Declared outside of Ajax.Request(...) ? It must be something really stupid but I just don't understand ... Jeremie 2010/3/2 Sergiu Dumitriu ser...@xwiki.com 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=plainoutputSyntax=plain , 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/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Strange ajax + json issue
Hello, Can't it be a timing problem ? When using Firebug, the system has time to retrieve result from the AJAX request but at execution time it has not ? -Message d'origine- De : users-boun...@xwiki.org [mailto:users-boun...@xwiki.org] De la part de Jeremie BOUSQUET Envoyé : mardi 2 mars 2010 08:30 À : XWiki Users Objet : Re: [xwiki-users] Strange ajax + json issue Hello thx Sergiu, I changed to json content-type, and responseJSON as you proposed. I checked that my GET request is 200 OK, and in the response the JSON tab in Firebug shows well formed JSON. But still my json variable is empty at execution time ! By the way if I breakpoint on or before the Ajax.Request() and step over the code, the json variable gets properly initiated and executed. Where it's used afterwards, it's perfectly well formed. I also added url parameters as 'parameters' of Ajax.Request instead of directly in the url but no change. Could it be a problem in the way I pass my json variable ? Declared outside of Ajax.Request(...) ? It must be something really stupid but I just don't understand ... Jeremie 2010/3/2 Sergiu Dumitriu ser...@xwiki.com 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=pl ainoutputSyntax=plain , 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/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users This e-mail is intended only for the addressee named above. It does not bind the sender, except in the case of an existing written convention with the addressee. This e-mail may contain material that is confidential and privileged for the sole use of the intended recipient. Any review, reliance or distribution by others or forwarding without express permission is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender and delete all copies. While reasonable precautions have been taken to ensure that this e-mail and any attachments are free from any computer virus or similar defect, no liability will be accepted in that respect. Anyone accessing this e-mail must take their own precautions as to security and virus protection. KBL European Private Bankers S.A., 43 boulevard Royal L-2955 Luxembourg, R.C.S. Luxembourg B 6395, T (352) 47 97 1 ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users