Thank you for your solutions.
Are we obliged to use jason ? Is it possible to stay "html" ?

On 9 fév, 19:42, Ryan <zen...@gmail.com> wrote:
> What? Sorry, but this is hard to understand. I believe you're trying
> to set element data from a value in a php file, right? If so, that's
> pretty easy using JSON.
>
> In PHP, json_encode() converts an array or object into a string, and
> in Javascript it takes that string and converts it to an object. Using
> the json dataType in jQuery.ajax, the success param will be the object
> converted from string to an object. The object keys will be the values
> from the PHP array.
>
> jQuery:
>
> $.ajax({
>         type: 'POST',
>         url: 'ajax.php',
>         dataType: 'json',
>         success: function(jdata){
>                 $('#element1').text(jdata.value1);
>                 $('#element2').text(jdata.value2);
>         }
>
> });
>
> PHP:
>
> echo json_encode(array('value1' => 'i\'m value 1', 'value2' => 'i\'m
> value 2'));
>
> On Feb 9, 1:27 pm,phicarre<gam...@bluewin.ch> wrote:
>
> > I would like to modify two jquery elements in the same time from PHP
> > module. The PHP module is called by .ajax
>
> > $.ajax(
> >     {
> >         type: "POST",
> >         url:'my_module.php',
> >         dataType: 'html',
> >          success: function(resultat) { ***** ????? *****},
> >         error: function(requete,iderror) {alert(iderror);}
> >     })
>
> > }
>
> > <div id=field1>...
> > <div id=field2>...
>
> > PHP code:
>
> > echo " ***new value for field1 **** new value for field2 *** "
>
> > How to formulate the success function AND the echo instruction ?

Reply via email to