Prototype, JSON and headers

Skip to first unread message


Aug 10, 2008, 4:35:31 PM8/10/08
to Ruby on Rails: Spinoffs
Hi everyone.
I love JSON and using Prototype has help me reduce the code to handle
AJAX responses.
But one thing keeps me confused and sometimes even frustrated.
I don't really understand what is going on with the headers, so if
someone could take some time to explain what is going on, I (and
probably a lot more people) would be very thankful.
The thing is this. On my local server (Mac OS Leopard Server 10.5.4,
PHP 5.2.5 by, Apache 2.2 Apple's default) after trying
different approaches, I finally got JSON to work using this:
$json = json_encode($status);
and my javascript to handle the JSON response:
onSuccess: function(transport,json) {
Beautiful, works great, on my Mac at least

When I upload this to the server, it doesn't work.
I don't know what kind of machine it is, but it is running PHP 5.2.0
and Apache 2.2 and probably Linux.
After a few hours of searching on the net and trial/error, this
$json = json_encode($status);
header('Content-type: application/json');
echo $json;
And the javascript:
onSuccess: function(transport) {
var json = transport.responseText.evalJSON();

So, anyone knows WHY? I would really like to understand what is going
on here.
Thank you.

T.J. Crowder

Aug 11, 2008, 3:41:49 AM8/11/08
to Ruby on Rails: Spinoffs

This group is defunct (although it's worth searching the archives).
Please see the new better-named, spam-free, moderated group here:

Note that it's moderated, so your first post won't show up
immediately. Please be patient.
T.J. Crowder
tj / crowder software / com
Reply all
Reply to author
0 new messages