doudeng2057 2013-04-21 21:13
浏览 49
已采纳

jQuery - 如何将数组从PHP发送到html文本框

I want to autofill the user form when a user is selected. How can I pass through an array from php to javacript/jquery and then put the values into the correct textboxes?

$("#client").change(function() {
     $.get("../jquery/update_client.php?id=" + $("#client").val(),function(data){
          $("#first").val(data);
     });
});

PHP file:

if(isset($_GET['id'])){
include('../db_connect.php');
$id = mysqli_real_escape_string($mysqli, $_GET['id']);
$query = "SELECT * FROM users WHERE iduser=$id LIMIT 1";
$result = $mysqli->query($query);
$row = $result->fetch_array();
echo $row[];
}

How can I capture the array in javacript/jquery and then parse the information to go into the right boxes?

  • 写回答

3条回答 默认 最新

  • dsgdsf12312 2013-04-21 21:16
    关注

    In PHP;

    echo json_encode($row);
    

    In JavaScript you will now get a map (array) back as data. This map you can then loop to fill your textbox(es).

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!