Re: [Proto-Scripty] Re: ajax.updater - json to fill select

2011-06-07 Thread Matt Petrovic
Updater expects the return result to be (X)HTML. It drops the response 
directly into the container as is. You should be returning an HTML string, 
or using Ajax.Request to get the JSON, convert it into HTML and dropping it 
in place.

If you want to be hackish about it, you do your converting in your 
OnSuccess, then save it to the .responseText property on the transport. But 
that's like hammering a nail with a screwdriver. 

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/prototype-scriptaculous/-/VklwMFVGNUdXcTRK.
To post to this group, send email to prototype-scriptaculous@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=en.



Re: [Proto-Scripty] Re: ajax.updater - json to fill select

2011-06-07 Thread Phil Petree
Jason,

I'm getting everything back from the php script just fine but I can not get
it into the select at all... I posted a new thread just a bit ago...
what I find is that if I use an onclick event to call my addOption function
with static data it works fine but if I call my function with static data
using the onSuccess of Ajax.updater the only thing that happens is the
select gets zero'd!

Phil

On Tue, Jun 7, 2011 at 4:13 PM, Jason jwestbr...@gmail.com wrote:

 Also make sure you exit; after the print json_ecode() so there is not
 additional output that will corrupt your JSON string

 Jason

 On Jun 6, 6:15 am, Eric lefauv...@gmail.com wrote:
  Hello,
 
  This is a little out of topic, but here are few hints:
  The easiest way to do that is to build a PHP array, and to use
  JSON_Encode to convert it into a JSON encoded string;
  You also need to change the content-type of your response to let
  prototype know it is actually JSON.
 
  Simple example:
  ?php
  $myCities = Array(Paris,Madrid,New-York,London);
  header('Content-Type: application/json');
  print json_encode($myCities);
  ?
 
  Eric
 
  On Jun 4, 11:15 am, Johan Arensman johanm...@gmail.com wrote:
 
 
 
 
 
 
 
   You can use basic Json, but this is basic javascript, not specific for
   prototype
 
   {
cars: [
 {
   make: 'some make name',
   models: [
 { name: 'model 1' },
 { name: 'model 2' }
   ]
 },
 {
   make: 'some other make name',
   models: [
 { name: 'model 3' },
 { name: 'model 4' }
   ]
 },
]
 
   }
 
   Something like this?
 
   Greets,
Johan
 
   On Fri, Jun 3, 2011 at 9:31 PM, Phil Petree phil.pet...@gmail.com
 wrote:
Hey All!
 
I'm biting the bullet and trying to break away from XML and go to
 json.
 
I using Ajax.Updater to call cities.php which looks up the available
 cities
for a given zip code (yes there can be more than one city - my zip
 has 4
possibilities!) and return those in a select
 
How do these need to be returned/formatted in php?
 
Can anyone point me to one of the car/make/model examples?  I can't
 find
one for prototype...
 
Thanks,
 
Pete
 
--
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-scriptaculous@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=en.

 --
 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-scriptaculous@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=en.



-- 
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-scriptaculous@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=en.



Re: [Proto-Scripty] Re: ajax.updater - json to fill select

2011-06-06 Thread Bertilo Wennergren
Eric lefauv...@gmail.com wrote:

 The easiest way to do that is to build a PHP array, and to use
 JSON_Encode to convert it into a JSON encoded string;

Yes, that's the right way.

If you aim for an associative array you should however watch out for a
particular gotcha: If such an array has members, it will turn into a
JSON/Javascript _object_, which is exactly what you want, but if once
in a blue moon the associative PHP array happens to be empty, then you
won't get an empty JSON/Javascript object, but an empty
JSON/Javascript _array_! If you then do Object.keys(X).each() on that
supposed object, you'll get a nasty surprise. So always check if your
object is really an object. (I was bitten by this on several
occasions, and it hurt.)

-- 
Bertilo Wennergren
berti...@gmail.com http://bertilow.com

-- 
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-scriptaculous@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=en.