您现在的位置是:首页 > 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头部代码
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个步骤完成,一起来体验吧
本文标签:
很赞哦! ()
图文教程
相关源码
-
(PC+WAP)企业管理工程造价资产评估财务审计带留言网站模板本模板基于PbootCMS内核开发,为工程造价咨询、财务审计类企业量身打造,同时支持多行业快速适配。采用PC+WAP双端同步设计,数据实时互通,助您高效展示企业形象与服务能力。查看源码 -
(自适应)橙色家政服务清洁保洁服务pbootcms网站模板源码下载模板核心价值:基于PbootCMS内核开发的家政服务类网站模板,通过模块化设计展现服务项目、团队风采、服务案例等核心板块,突出时效预约、服务标准化展示等家政行业特性。查看源码 -
(自适应手机端)seo博客网站模板新闻资讯网站源码下载本模板为SEO博客及新闻资讯类平台深度定制,采用PbootCMS内核开发。通过模块化设计实现多行业快速适配,仅需替换图文内容即可转型为医疗、教育、科技等领域网站。响应式布局确保在手机、平板等设备上获得一致浏览体验。查看源码 -
(自适应)品牌策划网络设计作品公司个人pbootcms网站源码下载本款基于PbootCMS开发的网站模板专为品牌策划、设计公司打造,特别适合展示创意作品、设计案例和企业服务。模板采用现代化设计风格查看源码 -
(PC+WAP)蓝色玻璃纤维制品环保设备营销型pbootcms模板源码下载这是一款针对玻璃纤维行业特点设计的网站模板,采用蓝色系配色方案,体现工业感和环保理念。模板包含产品中心、应用案例、技术支持和新闻动态等核心模块,能够全面展示玻璃纤维制品的技术参数和应用场景。查看源码 -
(PC+手机)帝国cms7.5漫画图片连载网站源码免费下载本模板基于帝国CMS7.5深度开发,为漫画阅读类网站打造。整体设计风格贴合漫画行业特性,界面布局充分考虑漫画作品的展示需求,支持多种漫画阅读模式。模板采用响应式设计,能够自动适配PC端和移动端设备,为读者提供流畅的阅读体验。查看源码
| 分享笔记 (共有 篇笔记) |

