php fetching data using jquery without refreshing -


i fetching data mysql db using jquery. problem want data php in seprated form, separte field roll number, name , father name php. @ code

html , jquery:

<div id="name"> </div> <div id="fname"> </div>  <script src="http://code.jquery.com/jquery-2.1.4.min.js"> </script> <script>  $('input#rsubmit').on('click', function () { var rnum = $('input#rollno').val();   if ($.trim(rnum) != ''){       $.post('newdata.php', {rnum: rnum}, function(data){           $('div#name').text(data);       });   } }); </script> </body> 

php:

if (isset($_post['rnum']) === true && empty($_post['rnum']) === false){  $rollno = $_post['rnum']; $query = $con->query("select * students rollno='$rollno'"); $result = $query->fetch(pdo::fetch_assoc); if ($result == true){     echo "name: ".$result['name'];     echo "father name: ".$result['fathername']; }else{     echo "no result found"; }   } 

the problem want name , father name in separate div's. gives both name , father name in #name div

try returning json php.

$user = array(); $result = $query->fetch(pdo::fetch_assoc);  $user['name'] = $result['name']; $user['father_name'] = $result['fathername'];   echo json_encode($user); 

it return [{name:'abc', father_name:'xyz'}] can access json data wherever want.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -