簡體   English   中英

如何比較具有相同ajax的兩個值?

[英]How to compare two values with same ajax?

我可以使用 ajax 比較一個下拉值,但無法比較同一個 ajax 中的兩個值。 可以通過將兩個值傳遞給 ajax 頁面 URL 或將兩個 id 傳遞給 ajax 函數。我想比較 op_attend 表中存在的日期和操作員 ID,並檢查同一個表中的出勤情況並相應地顯示下拉列表考勤領域。 所有這些 ajax 事件都應該在點擊任何按鈕之前發生。請幫幫我!!

 $('#category-list').on('change', function() { var state_id1 = this.value; $.ajax({ type: "POST", url: "checkop.php", data: 'state_id1=' + state_id1, success: function(result) { $("#attend1").html(result); } }); });
 <label>Date&nbsp;<span style="font-size:medium;color:red">*</span></label> <div class="input-group"> <input type="text" id="datepicker-autoclose" placeholder="dd-mm-yyyy" name="date2" class="complex-colorpicker form-control" required="" autocomplete="off"> </div> <label>Operator Name&nbsp;<span style="font-size:medium;color:red">*</span></label> <select class="select2 form-control custom-select" name="operator1" id="category-list" required=""> <option value="">Please Select</option> <?php require_once("dbcontrollernew.php"); $db_handle1 = new DBController(); $queryoperator ="SELECT * FROM operator where status='1'"; $operators = $db_handle1->runQuery($queryoperator); foreach($operators as $op) { ?> <option data-price7="<?php echo htmlentities($op['id']);?>" value="<?php echo htmlentities($op['operator']);?>"> <?php echo htmlentities($op['operator']);?> </option> <?php } ?> </select> <input id="opid1" style="display:none" name="opid1"> <label>Attendance&nbsp;<span style="font-size:medium;color:red">*</span></label> <select name="attendance1" id="attend1" class="select2 form-control custom-select" required=""> <option value="">Please Select</option> </select>

<?php
$sfid1 = ($_REQUEST['state_id1']); 
if($sfid1!='')
{
$drawing_result1 ='select * from op_attend where opid='.$_GET['state_id1'].';
 $result1=mysqli_query($con,$drawing_result1);
while($row1 =mysqli_fetch_assoc($result1)) { ?>
<option value="<?php echo $row1['attendance'];?>"><?php echo $row1['attendance'];?></option>
<?php }
}
?>

在ajax中,我們必須同時傳遞日期操作符ID

$('#category-list').on('change', function() {
  var state_id1 = $(this).val();
  $.ajax({
    type: "POST",
    url: "checkop.php",
    data: {'state_id1': state_id1, 'date' : $('#datepicker-autoclose').val()},
    success: function(result) {
      $("#attend1").html(result);
    }
  });
});

使用 post 方法獲取日期和操作員 ID:

<?php
$state_id1 = ($_POST['state_id1']); 
if($state_id1!='')
{
    $drawing_result ='select * from op_attend where opid='.$state_id1.' and date='.date('Y-m-d',strtotime($_POST['date']));
    $result1=mysqli_query($con,$drawing_result);
    $opt='';
    $opt.="<option value=''>Select Attendance</option>";

    while($row1 =mysqli_fetch_assoc($result1)) { 
        $opt.="<option value=".$row1['attendance_id']." >".$row1['attendance']."</option>";
    }
    echo $opt;
}
?>

希望這對你有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM