下面由thinkphp框架教程欄目給大家介紹thinkphp中ajaxReturn的用法 ,希望對(duì)需要的朋友有所幫助!
1.例子:
if ($codeid = $model->addCustomer($this->admin["id"])) { $data["code"] = 10000; $data["message"] = "添加客戶成功??蛻艟幪?hào)為:{$codeid}"; $data["data"] = 0; $this->ajaxReturn($data); } else { $data["code"] = 10001; $data["message"] = $model->failAddCustomer(); $data["data"] = 0; $this->ajaxReturn($data); }
2.返回?cái)?shù)據(jù):
$data
3.接收數(shù)據(jù)。
例如:
$.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(); } } });