Loading ...
Sorry, an error occurred while loading the content.

json object in header for prototype's auto-parsing

Expand Messages
  • David H. Young
    I thought I d post this for anybody who was struggling like me, trying to figure out how to get a json object generated in a java servlet (leveraging json.org
    Message 1 of 1 , Feb 15, 2007
    • 0 Attachment
      I thought I'd post this for anybody who was struggling like me, trying
      to figure out how to get a json object generated in a java servlet
      (leveraging json.org classes) into the header labeled as 'x-json'.

      I wanted to take advantage of prototype http://www.prototypejs.org and
      its auto-unmarshalling of a json object when returned in an
      AJAX.request() callback.

      Finally got it to work when I did the following:
      response.setHeader("Cache-Control", "no-cache");
      response.setHeader("X-JSON", json.toString());
      ...
      All of a sudden my dereferences on the browser/client side went from
      null to a real javascript dereference'able object:

      var formParms = Form.serialize('loginForm') + '§ion=create';
      var url = 'enlightener/';
      var parms = {
      parameters: formParms,
      onSuccess: function(resp, json) {
      alert('onSuccess: json status is ' + json.RESULT);
      ...

      Would love to hear from anybody else who's been taking this approach
      and what your experiences have been. And any tips that might help me
      along the way. It's fun right now. I'm a bit concerned about the 1K
      limit on json messaging (when using the header), but I can picture
      alternatives at that point.

      Between JSON, Ajax and Prototype, I'm enjoying programming all over again.

      David
    Your message has been successfully submitted and would be delivered to recipients shortly.