旧行李 2018-08-04 00:30 采纳率: 25%
浏览 21

在ajax中击退两个成功

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)

  • 写回答

1条回答 默认 最新

  • weixin_33701617 2018-08-04 00:36
    关注

    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);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP