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 <http://en.wikipedia.org/wiki/Rhodopsin> are cool. :-)
On Wed, Mar 11, 2009 at 8:35 AM, Dan Svoboda <dsvoboda(a)structbio.pitt.edu>wrote;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:
<!-- AJAX Web Service Call -->
<script type="text/javascript">
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);
}
} );
}
</script>
I call the function from an anchor tag: <a
href="javascript:getRenderedDoc()">Test Ajax</a>
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