Я использую CakePHP 2x.есть модель врача и назначение.В приемной диспетчер приемной может создать назначение.Когда он выбирает врача динамически, он показывает врачу visit_start и visit_end в форме записи из таблицы докторов через ajax.Но в моем коде не работает функция ajax.Пожалуйста, помогите мне разобраться с проблемой.Спасибо
таблица базы данных врачей
Это представление admin_add встреч.
<div class="appointments form">
<?php echo $this->Form->create('Appointment'); ?>
<fieldset>
<h2><?php echo __('Create Appointment'); ?></h2>
<?php
echo $this->Form->input('doctor_id', array(
'id' => 'doctor_id',
'empty' => '-----Select Doctor-----' ));
?>
<div id="visit">
</div>
<?php
echo $this->Form->input('patient_id');
echo $this->Form->input('appointed_time');
?>
</fieldset>
<?php echo $this->Form->end(__('Create')); ?>
</div>
<!-- document javascripts -->
<script type="text/javascript">
$(document).ready(function () {
$('#doctor_id').change(function(){
$doctor_id= $('#doctor_id :selected').val();
alert($doctor_id);
$.ajax({
type: 'POST',
url: "<?php echo Router::url(array('controller' => 'doctors',
'action' =>'get_by_doctor'), true); ?>",
cache: false,
data: doctor_id,
success: function(data) {
document.getElementById("#visit").innerHTML = response;
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
return false;
});
});
</script>
<?php
DoctorsController
public $components = array(
'Acl',
'Auth',
'Session',
'Security',
'Cookie',
'Paginator',
);
public $helpers = array('Html', 'Form', 'Js');
// AJAX
public function admin_get_by_doctor($id=null) {
$doctor_id = $this->request->data['Doctor']['doctor_id'];
$doctor = $this->Doctor->find('first', array(
'conditions' => array('Doctor.doctor_id' => $doctor_id),
));
$this->set('doctor',$doctor);
$this->layout = 'ajax';
}
ajaxview
<dt><?php echo __('Visitting Starts'); ?></dt>
<dd id="visit_start"><?php echo h($doctor['Doctor']['visit_start']); ?
> </dd>
<dt><?php echo __('Visitting Ends'); ?></dt>
<dd id="visit_end"><?php echo h($doctor['Doctor']['visit_end']); ?> </dd>
Встреча была создана, но на странице добавления не отображалось расписание врачей.Я хочу назначить встречу, зная время, когда доктор visit_start и доктор visit_end.