jquery array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    #16
    nope man it did not work :(

    see the code
    jquery code:

    Code:
    $("#patient_id").change(function(){
    $.post("/diabetes/patient_detail_change.php",{ location:$("#location").val(),doctor:$("#doctor").val(),patient_id:$("#patient_id").val()} ,function(json_data){
    
    alert(json_data);
    
    $.each(json_data, function(key,value){
    alert(key + ': ' + value);
    if(key == 'Name'){ $("#name").val(value);}
    if(key == 'Age'){ $("#age").val(value);}
    if(key == 'Weight'){ $("#ropweight").val(value);}
    if(key == 'Gest_age'){ $("#gest_age").val(value);}
    
    });
    
    });
        });
    the alert(json_data ); line prints this

    {"Patient_id":" R00008","Name": "","Age":"12"," Weight":"67","G est_age":"2"}

    but the alert(key + ': ' + value); is printing like
    0:{ 1:P 2:a and so on .

    the php code is like this and as u pointed out i have corrected the variable and array issue
    Code:
    <?php
    include_once('db.php');
    $location = $_POST['location'];
    $doctor = $_POST['doctor'];
    $patient_id = $_POST['patient_id'];
    if(($location != "") && ($doctor != "")){
    $sql = "select Name,Age,Gest_age,Weight from rop_form where Location = '".$location."' and Doctor = '".$doctor."' and Patient_id = '".$patient_id."'";
    $result = mysql_query($sql);
    $myresult  = "";
    while($row = mysql_fetch_array($result))
            {
            $myresult1['Patient_id'] = 'R'.$patient_id;
            $myresult1['Name'] = $row['Name'];
            $myresult1['Age'] = $row['Age'];
            $myresult1['Weight'] = $row['Weight'];
            $myresult1['Gest_age'] = $row['Gest_age'];
            }
            $myresult = json_encode($myresult1);
    }
    else
    {
    $myresult .= "";
    }
    echo $myresult;
    ?>

    Comment

    • zorgi
      Recognized Expert Contributor
      • Mar 2008
      • 431

      #17
      Code:
      $.getJSON("/diabetes/patient_detail_change.php", function(json_data){ $.each(json_data, function(i){alert(i + ":" + this)})})
      Hope this works

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #18
        nope.its not printing anything at all now after adding getJSON

        Comment

        • zorgi
          Recognized Expert Contributor
          • Mar 2008
          • 431

          #19
          $_GET instead of $_POST.

          More info about getJSON here

          Comment

          • pradeepjain
            Contributor
            • Jul 2007
            • 563

            #20
            hii i had to use something like

            Code:
            $("#patient_id").change(function(){
            $("#name").val('');
            $("#Age").val('');
            $("#ropweight").val('');
            $("#Gest_age").val('');
            
            $.getJSON (
              "/diabetes/patient_detail_change.php",
              { 
                location:$("#location").val(),
                doctor:$("#doctor").val(),
                patient_id:$("#patient_id").val()
              }, 
            
              function (json_data){
            
                if (json_data.Name) { $("#name").val(json_data.Name);}
                if (json_data.Age) { $("#age").val(json_data.Age);}
                if (json_data.Weight) { $("#ropweight").val(json_data.Weight);}
                if (json_data.Gest_age) { $("#gest_age").val(json_data.Gest_age);}
              }, 
              "Json"
            );
            });
            and $_GET in the php file. :).thanks for all the help!

            Comment

            Working...