我有加数行动及其视图,其中我有4个选择选项城市,专业,医院,医生。现在我需要的是,一旦我选择了最后一个选项,ajax调用就会运行,并且在同一页面上的所有细节包括医生visitdays,from和to_time动态地从数据库。 DoctorScheduleend()动作视图未创建! 我有这个代码但是找不到问题出在哪里! PLZ有耐心,帮帮我们吧!
模型:
<?php
class DoctorSchedule extends AppModel {
public $name='DoctorSchedule';
public $validate = array(
'name' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A State Name is required'
)
),
'country_id' => array('notempty' => array(
'rule' => array('notempty'),
'message' => 'Please Select Country'
),
)
);
public $belongsTo = array(
'Doctor' => array(
'className' => 'Doctor',
"foreignKey" => 'doctor_id'
),
'Office' => array(
'className' => 'Office',
"foreignKey" => 'office_id'
)
);
EnduserController :: doctorscheduleend()
public function doctorscheduleend()
{
$this->layout = 'ajax';
$this->autoRender = false;
$this->loadModel('DoctorSchedule');
$this->loadModel('Doctor');
$this->loadModel('Office');
$doctor_name = $this->Doctor->find('all',array('fields'=>array('Doctor.first_name','Doctor.last_name'),'conditions'=>array('Doctor.id'=>$_POST['DoctorId'])));
$this->set('doctor_name',$doctor_name);
foreach($doctor_name as $row)
{
$doctor_first_name = $row['Doctor']['first_name'];
$doctor_last_name = $row['Doctor']['last_name'];
}
$schedule = $this->DoctorSchedule->find('all',array('fields'=>array('DoctorSchedule.office_id','DoctorSchedule.visitdays','DoctorSchedule.from_time','DoctorSchedule.to_time'),'conditions'=>array('DoctorSchedule.doctor_id'=>$_POST['DoctorId'])));
$office_id = $visitdays = $from_time = $to_time = $officename= "";
foreach($schedule as $row)
{
$office_id = $row['DoctorSchedule']['office_id'];
$visitdays = $row['DoctorSchedule']['visitdays'];
$from_time = $row['DoctorSchedule']['from_time'];
$to_time = $row['DoctorSchedule']['to_time'];
}
$office = $this->Office->find('all',array('fields'=>array('Office.office_name'),'conditions'=>array('Office.id'=>$office_id)));/*editted here $officeid to ['$office_id']*/
$this->set('officename', $office);
foreach($office as $row)
{
$officename = $row['Office']['office_name'];
}
$tablerows = "";
$tablerows.= "<tr>
<td colspan='4' style='color:white;'>Schedule Of Dr. ".$doctor_first_name." ".$doctor_last_name."</td>
</tr></br>
<tr>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>Hospital</th>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>Visitday</th>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>From</th>
<th width='20%' align='center' valign='middle' bgcolor='#0c884b'>To</th>
</tr></br>
<tr>
<td>".$officename."</td>
<td>".$visitdays."</td>
<td>".$from_time."</td>
<td>".$to_time."</td>
</tr>";
echo $tablerows;
}
ajax查询:
$('#DoctorId').on('change',function()
{
if($('#CityId').val()!='')
{
if($('#SpecialtyId').val()!='')
{
if($('#OfficeId').val()!='')
{
$.ajax(
{
dataType: 'text',
cache: 'false',
url:'<?php echo Router::url(array('controller'=>'Enduser','action'=>'doctorscheduleend'));?>',
type: 'POST',
data : {"DoctorId": $('#DoctorId').val()},
evalScripts : true,
success: function (response)
{
var y = document.getElementById("ScheduleList").rows.length;
if(y!=0)
{
for(var i=0;i<1;i++)
{
$('#ScheduleList tr').remove();
}
}
$('#ScheduleList').append(response);
},
error: function (xhr, ajaxOptions, thrownError)
{
// showMessage("Error in ajax call.", 'error');
}
});
}
}
}
});
答案 0 :(得分:0)
请按照以下步骤操作:
步骤1:使用mozilla firefox中的firbug检查ajax请求
http://localhost/YOUR URL
Check response
步骤2:如果它成功完成然后检查,输出是什么,是否是您想要的输出或其他输出。 第3步:如果需要,请检查更新div和javascript代码。 步骤4:如果输出不正确,请调试微观级别的处理,例如在每行之后引入echo然后检查.....