Ajax响应后如何获取选定的值

时间:2019-04-10 06:25:21

标签: php ajax select response return-value

我的php代码有问题。 我需要从AJAX获取的默认选定值。

Jquery

    $('#select2').change(function() {
          var met_pemb = $('#met_pemb').val();
          var fund_D = $('#select2').val();
          var ccy = $('#ccy').val();
          var tmpt='';
            $.ajax({
                    type: "GET",
                    url: "gethint_acct_no.php",             
                    dataType: "html",
                    data: { ccy: ccy, fund: fund_D} ,   //expect html to be returned                
                    success: function(response){                    
                        $("#no_rek").html(response); 
                        alert($('select#no_rek:selected').val());               
                        }
                 });    
          var no_rek = $('select#no_rek').val();
           alert(no_rek);
            $.ajax({
                    type: "GET",
                    url: "gethint_gld1_settle.php",             
                    dataType: "html",
                    data: { no_rek: no_rek, fund: fund_D} ,   //expect html to be returned                
                    success: function(response){                    
                        $("#gl_d1").html(response); 
                     }
                 });                        
        });
    });

gethint_acct_no.php

<?php

 include "connect.php";
 session_start();
$ccy = trim(strip_tags($_GET['ccy']));

$fund = trim(strip_tags($_GET['fund']));

$qstring = "select distinct rek_no from rekening where bank = '".$fund."' and ccy = '".$ccy."'";
$result = mysqli_query($con,$qstring);
$found=mysqli_num_rows($result);
$itung=1;
if($found>0) {
    echo "<select name='no_rek' id='no_rek'>";
 while ($row = mysqli_fetch_assoc($result)) {
    echo "<option value='".$row['rek_no']."' name ='".$row['rek_no']."' id='".$row['rek_no']."'>".$row['rek_no']."</option>";
}
    echo "</select>";
}else
{
    echo "<input name='no_rek' type='text' id='no_rek' value='0'  />";
}

?>

HMTL

                    <tr>
                    <td width="144">Settlement Ref</td>
                    <td width="159"><input type="text" name="settle_ref" id="settle_ref" readonly="readonly"/></td>
                    <td width="159">Source Of Fund </td>
                    <td width="159"><select name="select2" id="select2">
                            <?php
    $sql = "select distinct bank from rekening order by bank";
    $result = $con->query($sql) or trigger_error($con->error."[$sql]"); 
    $itung1 =1;
    while ($r1=$result->fetch_array(MYSQLI_BOTH))
        {?>

<option value="<?php echo $r1['bank'];?>" name ="<?php echo $r1['bank'];?>" id="<?php echo $r1['bank'];?>"><?php echo $r1['bank'];?></option>
<?php
        }
    $itung1++;  
?></select></td>
                    </tr>
                    <tr>
                    <td>Settlement Amount</td>
                    <td><input type="text" class="money4" name="settle_amnt" id="settle_amnt"/> </td>
                    <td>&nbsp;</td>
                    <td><div id="no_rek" name="no_rek">
                    <select name="no_rek" id="no_rek"><option value="Kas" name ="Kas" id="Kas">Kas</option></select>
                    </div></td>
                    </tr>

预期结果是:

  1. 当我改变资金来源时,
  2. 然后按照相同的顺序,我将从no_rek获取默认值,并使用它来获取另一个值。

在这种情况下请帮助我。

预先感谢

0 个答案:

没有答案