您现在的位置是:首页 > cms教程 > 帝国CMS教程帝国CMS教程

帝国CMS全站alert弹窗改json格式输出的方法示例

晓巧2025-10-14帝国CMS教程已有人查阅

导读帝国CMS全站alert弹窗改JSON格式输出,不影响原版功能。1、在要输出json头部代码2.改造printerror和printerror2,增加一个参数$statuscode,不写的状态200

帝国CMS全站alert弹窗改JSON格式输出,不影响原版功能。
1、在要输出json头部代码
define('API_WORK', true);
2.改造printerror和printerror2,增加一个参数$statuscode,不写的状态200
/**
* cighsen02 365182575 弹窗改 json接口,还支持 404, 401等
* time: 2022.09.15
*/
//错误提示
function printerror($error="",$gotourl="",$ecms=0,$noautourl=0,$novar=0, $statuscode = 200){
global $empire,$editor,$public_r,$ecms_config;
if($editor==1){$a="../";}
elseif($editor==2){$a="../../";}
elseif($editor==3){$a="../../../";}
else{$a="";}
if($ecms==1||$ecms==9)
{
$a=ECMS_PATH.'e/data/';
}
if(strstr($gotourl,"(")||empty($gotourl))
{
if(strstr($gotourl,"(-2"))
{
$gotourl_js="history.go(-2)";
$gotourl="javascript:history.go(-2)";
}
else
{
$gotourl_js="history.go(-1)";
$gotourl="javascript:history.go(-1)";
}
}
else
{$gotourl_js="self.location.href='$gotourl';";}
if(empty($error))
{$error="DbError";}
if($ecms==9)//前台弹出对话框
{
@include $a.LoadLang("pub/q_message.php");
$error=empty($novar)?$qmessage_r[$error]:$error;
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
echo"<script>alert('".$error."');".$gotourl_js."</script>";
db_close();
$empire=null;
exit();
}
elseif($ecms==8)//后台弹出对话框
{
@include $a.LoadLang("pub/message.php");
$error=empty($novar)?$message_r[$error]:$error;
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
echo"<script>alert('".$error."');".$gotourl_js."</script>";
db_close();
$empire=null;
exit();
}
elseif($ecms==7)//前台弹出对话框并关闭窗口
{
@include $a.LoadLang("pub/q_message.php");
$error=empty($novar)?$qmessage_r[$error]:$error;
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
echo"<script>alert('".$error."');window.close();</script>";
db_close();
$empire=null;
exit();
}
elseif($ecms==6)//后台弹出对话框并关闭窗口
{
@include $a.LoadLang("pub/message.php");
$error=empty($novar)?$message_r[$error]:$error;
echo"<script>alert('".$error."');window.close();</script>";
db_close();
$empire=null;
exit();
}
elseif($ecms==0)
{
@include $a.LoadLang("pub/message.php");
$error=empty($novar)?$message_r[$error]:$error;
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
@include($a."message.php");
}
else
{
@include $a.LoadLang("pub/q_message.php");
$error=empty($novar)?$qmessage_r[$error]:$error;
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
@include($a."../message/index.php");
}
db_close();
$empire=null;
exit();
}
/**
* cighsen02 365182575 弹窗改 json接口,还支持 404, 401等
* time: 2022.09.15
*/
//错误提示
2:直接文字
function printerror2($error='',$gotourl='',$ecms=0,$noautourl=0, $statuscode = 200){
global $empire,$public_r;
if(strstr($gotourl,"(")||empty($gotourl))
{
if(strstr($gotourl,"(-2"))
{
$gotourl_js="history.go(-2)";
$gotourl="javascript:history.go(-2)";
}
else
{
$gotourl_js="history.go(-1)";
$gotourl="javascript:history.go(-1)";
}
}
else
{$gotourl_js="self.location.href='$gotourl';";}
if($ecms==9)//弹出对话框
{
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
echo"<script>alert('".$error."');".$gotourl_js."</script>";
}
elseif($ecms==7)//弹出对话框并关闭窗口
{
//cighsen02 365182575
if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode);
echo"<script>alert('".$error."');window.close();</script>";
}
else
{
@include(ECMS_PATH.'e/message/index.php');
}
db_close();
exit();
}
3、使用自动加载功能和异常处理,以上3个步骤完成,一起来体验吧

本文标签:

很赞哦! ()

相关源码

  • (自适应)刷卡pos机数据移动支付设备电子科技pbootcms模板下载本模板为POS机设备制造商、移动支付终端服务商和科技企业设计,基于PbootCMS系统开发,提供完整的在线展示平台解决方案,满足支付设备行业特有的展示需求。查看源码
  • (自适应)工业机械制造设备网站pbootcms模板下载为机械制造、工业设备类企业设计,特别适合各类机械设备、生产线、工业自动化产品展示。采用响应式技术,确保在不同设备上都能清晰展示机械产品的技术参数和细节特点。查看源码
  • pbootcms模板(自适应手机版)红色响应式单位机构类网站自适应响应式单位机构网站模板 | PbootCMS内核开发为机构组织设计的响应式网站模板,采用PbootCMS内核开发,支持一键替换行业内容,满足多元化场景需求。查看源码
  • (PC+WAP)蓝色新能源环保太阳能光伏模板pbootcms下载新能源环保行业网站解决方案为太阳能光伏系统企业打造的专业网站模板,助力新能源企业高效展示产品与服务PbootCMS内核开发,源码开放可修改PC与手机端自适应设计查看源码
  • (自适应响应式)门窗定制门业带视频功能pbootcms模板下载本模板采用PbootCMS内核开发,为门窗制造、定制安装企业打造,通过可视化后台管理系统快速构建品牌官网。自适应设计确保在手机、平板、电脑等设备上均能获得优质浏览体验查看源码
  • 帝国CMS7.2互联网自媒体门户整站带数据源码免费下载分享一款高仿极客网门户模板,帝国cms7.2版本,非常适合互联网、自媒体、文章门户网站使用。测法发现备份数据恢复报错,找了几个版本的都是一样的,有能力的自行修复查看源码
分享笔记 (共有 篇笔记)
验证码: