html页面中发送一个ajax请求到服务端,实现静态无刷新提示并做数据处理操作!
此处json需要格式话一下,格式化之后$.ajax({
type:"POST",
url :"{#:U('Account/changeActiviteStatus')#}",
data:{ uid:id },
success:function(data,status){
json = JSON.parse(data) //格式化json 格式话之后,alert弹出的是 (object.object),
然后其他的用法,就和php的差不多了 alert(json.msg);
return false;
if(data.msg){ swal("error",data.msg); return false; }
swal("success","操作成功!"); //注释: swal是一个弹出插件
window.location.href="{#:U('AccountCodes/index','','')#}"; },
error:function(){ swal("error","发送请求失败,请重新操作!"); } });
php服务端处理(服务端直接把提示信息专程json数组,返回给页面即可,类似于这种:{“msg”:”\u66f4\u6539\u7528\u6237\u72b6\u6001\u5931\u8d25\uff01″})public function changeActiviteStatus(){
$uid = (string)I('uid',0);
$account = new AccountService();
$codes = new RegisterCodeService();
$res = $account->changeActiviteStatus($uid);
$bindCode= $codes->bindUidCode($uid);
if($res && $bindCode){ return true; }
elseif(!$res){ print_r(json_encode(array('msg'=>'更改用户状态失败!'))); }
elseif(!$bindCode){ print_r(json_encode(array('msg'=>'绑定申请码失败!'))); }
else{ print_r(json_encode(array('msg'=>'未知数据库错误!'))); } }