1.例子:
if ($codeid = $model->addCustomer($this->admin["id"])) { $data["code"] = 10000; $data["message"] = "添加客户成功。客户编号为:{$codeid}"; $data["data"] = 0; $this->ajaxReturn($data); } else { $data["code"] = 10001; $data["message"] = $model->failAddCustomer(); $data["data"] = 0; $this->ajaxReturn($data); }
2.返回数据:$data
3.接收数据。例如:
$.ajax({ type : "POST", url : "<?php echo U('policy/addCustomer'); ?>", dataType : "JSON", data : data, success : function(eve) { alert(eve.message); if (eve.code == 10000) { window.location.reload(); } } });