我的jquery提醒无效。我创建了两个模型 - MedicalBillRecover BelongsTo MedicalBill MedicalBill有很多MedicalBillRecover。
现在我在jquery ajax中有一个onchange事件
$('#recover_billDate_id').on('change',function(){
var employee_id=$('#employee_recover_bill_id').val();
var recover_billDate=$('#recover_billDate_id').val();
var data = 'recover_billDate='+recover_billDate+'&employee_id='+employee_id;
var url_to_call = '';
url_to_call = '<?php echo $this->Html->url(array("controller" => "medical_bills","action" => "render_recover_total_balance")); ?>';
$.ajax({
type: "GET",
url: url_to_call,
dataType: "json",
data: data,
error:function(resp){
alert('Oops..Something went wrong');
},
success: function(resp){
$.each(resp,function(index,obj){
alert(obj.MedicalBillRecover.recovery_payment_amount);
});
}
});
});
控制器:
function render_recover_total_balance(){
$this->autoRender = false;
Configure::write("debug",0);
$cond = '';
if(isset($_GET['employee_id']) && trim($_GET['employee_id']) != '') {
$employee_id = $_GET['employee_id'];
$recover_billDate = $_GET['recover_billDate'];
$cond['MedicalBill.employee_personal_id'] = $employee_id;
$cond['MedicalBill.bill_date'] = $recover_billDate;
}
$employees = $this->MedicalBill->find('all',array('conditions'=>$cond));
return json_encode($employees);
}
jquery警报不起作用。当我写url as- / gramin-vikash-bank-test / medical_bills / render_recover_total_balance?employee_id = 1&amp; recover_billDate = 2014-04-22。
然后我得到结果
[{"MedicalBill":{"id":"2","employee_personal_id":"1","nature_of_disease":"er","bill_amount":"50000.00","bill_date":"2014-04-22","sanctioned_by_bank":"3.00","sanctioned_by_insurance_co":"3.00","temporary_advance_sanctioned":"100000.00","advance_date":"2014-04-21","ailing_person":"4"},"EmployeePersonal":{"id":"1",""category":"General", Nalbari","office_id":"1","department_id":"1","designation_id":"1","current_post":"","status":"1"},"MedicalBillRecover":[{"id":"1","medical_bill_id":"2","entry_date":"2014-04-22","recovery_payment_amount":"500.00","user_id":null},{"id":"2","medical_bill_id":"2","entry_date":"2014-04-23","recovery_payment_amount":"1000.00","user_id":null}]}]
现在我如何在jquery ajax警报中检索MedicalBillRecover.recovery_payment_amount。