my_module.php <?php $myArray = array( 'var1' => 'hello', 'var2' => 'world' ); echo json_encode($myArray); ?>
helloWorld.html $.ajax( { type: "POST", url:'my_module.php', dataType: 'json', // <!-- I'VE CHANGED THIS TO RECEIVE JSON AS RESPONSE success: function(resultat) { $("#field1").text(resultat.var1); $("#field2").text(resultat.va21); }, error: function(requete,iderror) {alert(iderror);} }) } <div id=field1></div> <div id=field2></div> On Feb 9, 8:27 am, 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 ?