I want to separate the result after requesting in ajax
<input type="text" class="form-control" name="userno" id='stud_id' readonly >
<input type="text"name="studentname" id='studentname' readonly >
<input type='submit' name='stud' onclick='showstudent_info()'>
function showstudent_info(){
var studid = $('#studid').val();
console.log(studid);
if(studid){
$.ajax({
type:'POST',
url:'parentinfo.php',
data: 'studid='+studid,
success:function(html){
var infoid = html
$('#stud_id').val(info);
var studname = html
$('#studentname').val(studname);
}
});
}
}
this is my parentinfo.php page
parentinfo.php
$stud_id = $_POST['studid'];
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl where
stud_id = $stud_id";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
$info = $row['stud_id'];
$studname = $row['Name'];
}
echo $info;
echo $studname;
my problem is the value of infoid and studname is joined e.g(1Albert Einstein)
Send it as JSON so you can break it up server side to make it readable as a javascript object client side instead of parsing a string sent from server
In php would be something like:
$outputArray = array(
'id'=> $idVariable,
'name'=> $nameVariable
);
echo json_encode($outputArray);
Then in js add dataType:'json'
to the ajax options and success callback would be something like:
success:function(responseObject){
var infoid = responseObject.id;
$('#stud_id').val(infoid );
var studname = responseObject.name;
$('#studentname').val(studname);
}