>From looking at the Prototype code, it looks like any text in the
''X-JSON'' header will be eval''d and passed as the
second parameter to
your onSuccess handler.
Your handler function could then be (using all the power of Prototype):
var handlerFunc = function(t, json)
{
// Update info container
Element.update(''someId'', json.foo);
}
But your JSON must be in the X-JSON header, not in the body of the
response for this to work.
-----Original Message-----
From: Dirk Eschler [mailto:eschler-zc1r9W/44D4b1SvskN2V4Q@public.gmane.org]
Sent: Thursday, December 22, 2005 1:56 AM
To: mail-yVS5avHIROZWk0Htik3J/w@public.gmane.org;
rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: Re: [Rails-spinoffs] Re: ajax - multiple updates on
singlexmlhttprequest
Am Mittwoch, 21. Dezember 2005 14:56 schrieb Marco M.
Jaeger:> Is there a way to use xml or json somehow - if yes, how? has anybody
done> this before?
I''ve successfully used JSON. Here''s a stripped down example:
// ---------------------------
// Handler function: is executed after successful Ajax.Request
var handlerFunc = function(t)
{
// Evaluate returned JSON data
var evalObj = eval(t.responseText);
// Update info container
$(''someId'').innerHTML = evalObj.foo;
}
// Bind the function and do the Ajax request
new Ajax.Request(''script.pl'', {
parameters: ''id=42'',
onSuccess: handlerFunc
});
// ---------------------------
In the example "evalObj.foo" matches "({foo:"bla
bla"})" in JSON. And
"bla
bla" will be written into the innerHTML part of the (X)HTML container
with
css id "someId". Hope that helps.
Let me just add here, that i''m pretty new to script.aculo.us myself, so
if
anyone knows a better way of doing this, please let me know. Like the OP
i''m
looking for a good XML example without Rails too.
--
Best Regards
Dirk Eschler
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs