doutangshuan6473 2012-07-20 15:42
浏览 36
已采纳

Ajax php jquery

I have an AJAX call on txt_RollNo's blur event to bring std_name,Class,age from database and fill it in txt_name,txt_class,txt_age.

In a single call can I have name,class,age all as a whole in array or any, how to seperate it.

$("#txt_RollNo").blur(function(){   
$.ajax({
            url:'getSudent.php',
            data:'stdID='+ $(this).val().trim(),
            success:function(array_from_php)
            {
            //but here i m receiving php array, how deal in jquery
                //$("#txt_name").val(array_from_php);
                //$("#txt_Class").val(array_from_php);
                //$("#txt_age").val(array_from_php);

            }
            })   
});

getSudent.php echos array as below

<?php   
  $qry=mysql_query("select * from students where studentID='".$_GET['std_ID']."'");   
  $row=mysql_fetch_array($qry);   
  echo $row;
?>
  • 写回答

2条回答 默认 最新

  • duanluo9369 2012-07-20 15:44
    关注

    PHP:

    <?php
      header('Content-type: application/json');
      $qry=mysql_query("select * from v_shop where shop_no='".$_GET['shopno']."'");   
      $row=mysql_fetch_array($qry);   
      echo json_encode($row);
    ?>
    

    JavaScript

    ...
    $.ajax({
        dataType: 'json',
        ...
        success:function(array_from_php){
            console.log(array_from_php); // WTF is this?
    

    See json_encode : http://php.net/manual/en/function.json-encode.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染