Sending Data in JSON-Format to the Client.

Hi everybody,
I'm a rookie in web engineering, especially with frontend & AJAX.
I send an request on the client-side per AJAX (Y.io) and want to answer him on the server-side, by sending data in JSON-format as response.

At the moment i'm doing this by having a template like this, calling it with ac.done({ foobar: foobar}):
"{{key}}": {{value}},
"": ""
which is imo really ugly, specially the last line to fulfill the JSON requirements.

My question: How can I send plain JSON data as response of an AJAX call?

PS: By sending data from the client to the server, I can send the js-object directly, unless it has nested object - than I can't access the keys/values of the nested object, I have to parse the object into a JSON string. Is that a XMLHttpRequest constraint?

1 Reply
  • Hi,

    Instead you can do ac.done({foobar: foobar}, 'json') and Mojito will skip the view and send the JSON directly.



Recent Posts

in Yahoo! Mojito