我正在尝试将内容添加到以下 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”
<?php
include '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++;
}
}
}
?>
狐的传说