Re: [xwiki-users] groovy web service

2009-03-11 Thread Niels Mayer
I'm not sure if this is directly related, but it might be. I had some weird
issues with unexpected wikifrobbing (basically acting as if the {pre} wasn't
there) of my json data that happened to contain HTML strings:
   http://nielsmayer.com/xwiki/bin/view/Timeline/YTTL-Mock-JSON?xpage=plain
that required me to do some oddball things in the code to prevent said
wikifrobbing:
   http://nielsmayer.com/xwiki/bin/view/Timeline/YTTL-Mock-JSON?viewer=code

I got sick of messing with JSON and now i just create the objects in
javascript directly, which is the way it needed to be done in the first
place for efficiency-sake.

It's possible something unexpected and similar is happening with your json
data. It might be a good idea to look at the JSON request/response in
firebug and see if your data is as expected.

Niels
http://nielsmayer.com

PS: Rhodopsins  are cool. :-)

On Wed, Mar 11, 2009 at 8:35 AM, Dan Svoboda wrote:

> I'm implementing some Ajax to change page content using a web service,
> and I'm stumped.
>
> Here's the web service code:
>
> <%
>   response.setContentType("application/x-json")
>
>   def success = "Successful Ajax Web Service call!"
> %>
> {
>  "rdoc": "<%=success%>"
> }
>
> Here's the javascript Ajax call:
>
> 
>
>   function getRenderedDoc() {
>   window.alert("Function Called");
> new Ajax.Request(
> // Here we make the asynchronous call to our previously
> created web service.
> // Note that we are using the XWiki API from velocity to
> compute the exact URL we want to hit.
> // This is possible since the entire page will be evaluated
> by the velocity engine before being sent to
> // the client from which this javascript function will be
> executed.
> // We precise the number of entries we want to retrieve using
> the limit parameter. The second parameter,
> // "xpage=plain" is mandatory, this force XWiki to render the
> called document with the "plain.vm" velocity
> // template, thus not returning the whole skin. If we forget
> this parameter, we will not receive a valid JSON
> // and our client will not work.
> "/1.8/bin/view/Main/WebService?xpage=plain",
> {
>   method: 'get',
>   onSuccess: function(transport) {
>// first, we evaluate the JSON result to make it
> manipulable as javascript objects
>var res = eval( '(' + transport.responseText + ')' );
>
>var rendcontent = res.rdoc;
>var rdiv = document.getElementById("div_Space_Rhodopsin");
>while( rdiv.childNodes.length >= 1 ) {
>  rdiv.removeChild( rdiv.firstChild );
>}
>
>var pTag = document.createElement("p");
>pTag.innerHTML = rendcontent;
>rdiv.appendChild(pTag);
>}
>} );
>   }
> 
> I call the function from an anchor tag:  href="javascript:getRenderedDoc()">Test Ajax
>
> The alert is displayed, but I'm not seeing any update on my page. All
> of the DOM manipulations have been independently verified with text
> literals outside of the Ajax.Request.
>
> Thanks.
>
> Dan Svoboda
>
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] groovy web service

2009-03-11 Thread Jerome Velociter
Hi

Dan Svoboda wrote:
> I'm implementing some Ajax to change page content using a web service,  
> and I'm stumped.
>
> Here's the web service code:
>
> <%
>response.setContentType("application/x-json")
>
>def success = "Successful Ajax Web Service call!"
> %>
> {
>   "rdoc": "<%=success%>"
> }
>
> Here's the javascript Ajax call:
>
> 
>   
>function getRenderedDoc() {
>window.alert("Function Called");
>  new Ajax.Request(
>  // Here we make the asynchronous call to our previously  
> created web service.
>  // Note that we are using the XWiki API from velocity to  
> compute the exact URL we want to hit.
>  // This is possible since the entire page will be evaluated  
> by the velocity engine before being sent to
>  // the client from which this javascript function will be  
> executed.
>  // We precise the number of entries we want to retrieve using  
> the limit parameter. The second parameter,
>  // "xpage=plain" is mandatory, this force XWiki to render the  
> called document with the "plain.vm" velocity
>  // template, thus not returning the whole skin. If we forget  
> this parameter, we will not receive a valid JSON
>  // and our client will not work.
>  "/1.8/bin/view/Main/WebService?xpage=plain",
>  {
>method: 'get',
>onSuccess: function(transport) {

Have you checked with Firebug the response is the JSON you expected ? 
You can

console.log(transport.responseText);

to make sure.

Hope this helps.
Jerome.

> // first, we evaluate the JSON result to make it  
> manipulable as javascript objects
> var res = eval( '(' + transport.responseText + ')' );
>
> var rendcontent = res.rdoc;
> var rdiv = document.getElementById("div_Space_Rhodopsin");
> while( rdiv.childNodes.length >= 1 ) {
>   rdiv.removeChild( rdiv.firstChild );
> }
>
> var pTag = document.createElement("p");
> pTag.innerHTML = rendcontent;
> rdiv.appendChild(pTag);
> }
> } );
>}
> 
> I call the function from an anchor tag:  href="javascript:getRenderedDoc()">Test Ajax
>
> The alert is displayed, but I'm not seeing any update on my page. All  
> of the DOM manipulations have been independently verified with text  
> literals outside of the Ajax.Request.
>
> Thanks.
>
> Dan Svoboda
>
>
>
> ___
> 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


[xwiki-users] groovy web service

2009-03-11 Thread Dan Svoboda
I'm implementing some Ajax to change page content using a web service,  
and I'm stumped.

Here's the web service code:

<%
   response.setContentType("application/x-json")

   def success = "Successful Ajax Web Service call!"
%>
{
  "rdoc": "<%=success%>"
}

Here's the javascript Ajax call:



   function getRenderedDoc() {
   window.alert("Function Called");
 new Ajax.Request(
 // Here we make the asynchronous call to our previously  
created web service.
 // Note that we are using the XWiki API from velocity to  
compute the exact URL we want to hit.
 // This is possible since the entire page will be evaluated  
by the velocity engine before being sent to
 // the client from which this javascript function will be  
executed.
 // We precise the number of entries we want to retrieve using  
the limit parameter. The second parameter,
 // "xpage=plain" is mandatory, this force XWiki to render the  
called document with the "plain.vm" velocity
 // template, thus not returning the whole skin. If we forget  
this parameter, we will not receive a valid JSON
 // and our client will not work.
 "/1.8/bin/view/Main/WebService?xpage=plain",
 {
   method: 'get',
   onSuccess: function(transport) {
// first, we evaluate the JSON result to make it  
manipulable as javascript objects
var res = eval( '(' + transport.responseText + ')' );

var rendcontent = res.rdoc;
var rdiv = document.getElementById("div_Space_Rhodopsin");
while( rdiv.childNodes.length >= 1 ) {
  rdiv.removeChild( rdiv.firstChild );
}

var pTag = document.createElement("p");
pTag.innerHTML = rendcontent;
rdiv.appendChild(pTag);
}
} );
   }

I call the function from an anchor tag: Test Ajax

The alert is displayed, but I'm not seeing any update on my page. All  
of the DOM manipulations have been independently verified with text  
literals outside of the Ajax.Request.

Thanks.

Dan Svoboda



___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users