我正在嘗試將內容添加到以下 div:<div id="radio-toolbar" class="radio-toolbar"></div> 使用此 AJAX 腳本:$('#part_code').keyup(function(){ $.ajax({ url: "binlist.php", data: {text: $(this).val()}, type: "POST", dataType:'json', success: function(data) { $("#radio-toolbar").html(data); } }); });我從中獲取數據的輸入是這個。寫入文本時,ajax 腳本會觸發:<input type="text" name="part_code" id="part_code" class="form-control" value="<?php echo $part;?>">Binlist.php 代碼在 SQL Server 中進行一些檢查,然后編寫 HTML 代碼。如果我硬設置 $part_code_for_bin 變量它會起作用,但是當我嘗試從 POST 獲取它時,我會收到錯誤“Undefined index: part_code”<?phpinclude 'code\database.php';include 'code\plant.php';//$part_code_for_bin = '1020';//$part_code_for_bin = '116-SIG-30622A-TSM260A';$part_code_for_bin = $_POST['part_code'];if(isset($part_code_for_bin)) { $sql_binlist= "SELECT BIS_BIN FROM R5BINSTOCK WHERE BIS_PART = '$part_code_for_bin' and BIS_STORE = '$store' and BIS_PART_ORG = '$org'"; $bins = sqlsrv_query($conn, $sql_binlist, array(), array( "Scrollable" => 'static')); $bins_count = sqlsrv_num_rows($bins); if ($bins_count > 1) { $result_bins = array(); $i = 0; while ($row = sqlsrv_fetch_array ($bins, SQLSRV_FETCH_ASSOC)) { $result_bins[] = $row['BIS_BIN']; ?> <input type="radio" id="<?php echo $result_bins[$i]?>" name="radioBin" value="<?php echo $result_bins[$i]?>" onclick="write_bin('<?php echo $result_bins[$i]?>');"> <label for="<?php echo $result_bins[$i]?>"><?php echo $result_bins[$i]?></label> <?php $i++; } }}?>
Ajax POST 或 PHP 中的未定義索引
慕桂英4014372
2023-03-04 18:09:58