Howto work with JSON in PHP and AJAX -


  1. i have form users can click selection of dropdown-box.
  2. depending on selection group of names must shown.

i believe step 1 best done in ajax step 2. after reading lot on internet believe best way using json-object. best way?

can explain me how make work?

you can send post request input parameters via ajax, return array of json objects php function ajax request calls (json easy parse in javascript).

something (assuming using jquery):

$.post('somepage.php',{'age':'18'},function(data,status){     if (data instanceof array) {         // clear display div         $('#displaydiv').html('');         // append items div         (var = 0; < data.length; i++) {             $('#displaydiv').append('<p>'+data[i].firstname+' '+data[i].lastname+'</p>');         }     } else {         return false;     } }); 

Comments