1

txt_RollNoblurイベントで AJAX 呼び出しを行い、データベースから , を取得してstd_name、,に入力します。Classagetxt_nametxt_classtxt_age

1回の呼び出しnameで、 、classageすべてを配列または任意にまとめて、それをどのように分離することができますか。

$("#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 は以下のように配列をエコーし​​ます

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

2 に答える 2

3

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?

json_encode を参照してください: http://php.net/manual/en/function.json-encode.php

于 2012-07-20T15:44:39.107 に答える