You could try $.each

$.ajax({
   type: "POST",
   url: "test.php",
   data: "query:edit&id="+idval,
   dataType: "json",
   success: function(data){
       $.each(data, function(index, value) {
            id = '#' + index;
            $(id).val(value); // does anyone know if this works?
       });
   }
 });



On 6/28/07, Renato Formato <[EMAIL PROTECTED]> wrote:
>
>
> Massimiliano Marini ha scritto:
> > Hi all,
> >
> > like in the subject, I do a query with $.ajax on a php file,
> > the query retrieve a "name" and a "surname", in which format I must send
> > out the data from my php file? And how I can manage this data to fill
> > in the appropiate field in my form?
> >
> > My actually jQuery code :
> > $.ajax({
> >   type: "POST",
> >   url: "test.php",
> >   data: "query:edit&id="+idval,
> >   success: function(data){
> >     //what code I must put inside here, first for reading the data
> >     //and next using it to fill the fields in my form?
> >   }
> > });
> >
> > The query in which format must send out the data?
> > Question: something like this is correct :
> > <?
> >   echo "{name:'pippo',surname:'pluto'}";
> > ?>
> >
> > Thanks for any help, advise and suggest.
> > --
> > Massimiliano Marini - http://www.linuxtime.it/massimilianomarini/
> > "It's easier to invent the future than to predict it."  -- Alan Kay
> >
>
> You can send back data in json, xml, html
>
> If you choose to use json (as you did in your example server side
> script) you can write something like this:
>
>   $.ajax({
>     type: "POST",
>     url: "test.php",
>     data: "query:edit&id="+idval,
>     dataType: "json",
>     success: function(data){
>         $("#name").val(data.name);
>         $("#surname").val(data.surname);
>     }
>   });
>
> Renato
>

Reply via email to