Hi,

> Since I work with prototypejs AJAX requests to return, I always return
> calls as application/json parsing the JSON object in the response, so
> I had to always use something like the following to use the object:
>
> var json = transport.responseText.evalJSON();

There's no need to do that. Just use the transport.responseJSON
property. Prototype detects  application/json responses, automatically
evaluating the JSON and populating that property with it. Calling
transport.responseText.evalJSON() just duplicates that effort.

> However in the documentation of prototype, to use the JSON object
> directly, they recommend using, for example:
>
> var json = transport.headerJSON;
>
> To proceed in this manner is necessary to write the header X-JSON
> object with the contents of the JSON...

This is just a useful way to send *additional* data related to the
response on top of the primary response. So for instance, you might
respond with text/html data but include an X-JSON header to supply
further information about it.

For what you're doing (an Ajax request specifically to get the data),
I don't see any advantage; just keep doing what you're doing server-
side and start using the responseJSON property.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Nov 19, 5:39 pm, Moisés Gramary Barbosa <moigram...@gmail.com>
wrote:
> Hello everyone, firstly thank you very much.
>
> I have the following questions:
>
> Since I work with prototypejs AJAX requests to return, I always return
> calls as application/json parsing the JSON object in the response, so
> I had to always use something like the following to use the object:
>
> var json = transport.responseText.evalJSON();
>
> However in the documentation of prototype, to use the JSON object
> directly, they recommend using, for example:
>
> var json = transport.headerJSON;
>
> To proceed in this manner is necessary to write the header X-JSON
> object with the contents of the JSON...
>
> My questions are:
>
> What improvements can I do with this method?
> PrototypeJS could not detect the response MimeType, as application/
> json, and interpret it the same?
> And last ... If I refactor my script to use the X-JSON header, the
> response of the request should be empty?
>
> Sorry for my English

--

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=.


Reply via email to