这里我根据selectbox值从数据库返回ajax值。我的脚本工作但是当我试图寻找阵列解决方案时,在ajax中发布值没有响应。为什么我没有获得价值?任何帮助将不胜感激。谢谢高级。
自动完成-ajax.php
<?php
if(isset($_POST['pr_code'])) {
$pr_code= $_POST['pr_code'];
$sql = $mysqli->query("SELECT * FROM purchase_request WHERE pr='$pr_code'");
while($row = $sql->fetch_assoc())
{
$approved= $row['approved'];
$requested = $row['requested'];
}
echo json_encode(array("approved" => $approved, "requested" => $requested));
}
?>
的index.php
<?php
$combo = $mysqli->query("SELECT * FROM purchase_request GROUP BY pr ORDER BY id");
$option = '';
while($row = $combo->fetch_assoc())
{
$option .= '<option value = "'.$row['pr'].'">'.$row['pr'].'</option>';
}
?>
<select id="tag"><option value="">wala</option><?php echo $option; ?></select>
<input name="requested" id="requested" type="text">
<input name="approved" id="approved" type="text">
<script type="text/javascript">
$(document).ready(function()
{
$('select[id="tag"]').change(function()
{
var pr_code = $("#tag").val();
$.ajax({
type: "POST",
url: "autocomplete-ajax.php",
data :"pr_code="+pr_code,
dataType:'text',
type:'POST',
success:function(data){
var approved=data.approved;
var requested=data.requested;
alert(approved);
$('#approved').val()=approved;
$('#requested').val()=requested;
}
});
return false;
});
});
</script>