2 回答
TA贡献1846条经验 获得超7个赞
您应该将数据作为 json 返回,然后使用它
$results=$query->fetchAll(PDO::FETCH_OBJ);
// remove all code after it, and add the following line
echo json_encode($results);
在你的 ajax 渲染选项中像这样
function getfee()
{
$.ajax(
{
url: "getfee.php",
data: {doctor : $("#get_doctor_name").val()},
type: "POST",
beforeSend: function() {
//start loader
$("#loaderIcon").show();
},
error: function() { // hide loader when error otherwise will stuck on your screen
$("#loaderIcon").hide();}
success: function(objJson)
{
var data = $.parseJSON(objJson);
console.log(data); // to view how it looks in console, array, empty or whatever
$('#get_doctor_fee').empty();
if(data.length > 0) {
$.each(data, function(key, value) {
$('#get_doctor_fee').append('<option value="'+ value.D_FEES+'">'+ value.D_FEES +'</option>');
});
} else {
$('#get_doctor_fee').append('<option value="">No Doctor in this specilization </option>');
$('#submit').prop('disabled',true);
}
$("#loaderIcon").hide();
},
});
}
您可以对其他下拉菜单应用相同的调整,它只是一个示例,向您展示如何管理它。
您可以更改的另一件事是调用您的函数,这样函数可以更可定制并具有更多控制权。但这取决于您的喜好
$('#get_doctor_name').on('change', function() {
// call your ajax here
...
url: "getfee.php",
data: {doctor : $(this).val()},
type: "POST",
...
// update get_doctor_fee here
})
$('#get_doctor_fee').on('change', function() {
// call your ajax here
...
url: "getslot-date.php",
data: {doctor : $(this).val()},
type: "POST",
...
// update get_date dropdown
})
TA贡献1860条经验 获得超9个赞
你必须像这样写数据
function getfee() {
$("#loaderIcon").show();
jQuery.ajax({
url: "getslot-date.php",
data: {doctor : $("#get_doctor_name").val()},
type: "POST",
success: function(data) {
$("#get_date").html(data);
$("#loaderIcon").hide();
},
error: function() {}
});
}
- 2 回答
- 0 关注
- 119 浏览
添加回答
举报
