您现在的位置是:首页 > 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个步骤完成,一起来体验吧

本文标签:

很赞哦! ()

相关源码

  • (自适应)绿色园林建筑花卉园艺艺术模板免费下载为景观设计及园艺企业打造的响应式网站框架,基于PbootCMS系统开发,帮助传统园林行业建立现代化数字展示平台。采用标准DIV+CSS前端架构,代码精简无冗余。查看源码
  • (自适应响应式)高端珠宝首饰奢侈品pbootcms模板下载本模板为珠宝首饰及奢侈品行业打造,采用PbootCMS内核开发,具备卓越的视觉表现力与商业转化能力。自适应设计确保在手机端呈现产品细节,后台数据实时同步,助您高效展示钻石查看源码
  • (自适应)简繁双语机械矿山矿石五金设备pbootcms源码下载本模板基于PbootCMS开发,主要面向机械五金、矿山矿石设备等行业,支持简体中文和繁体中文双语切换。采用响应式布局技术,确保在各种设备上都能获得良好的浏览体验。模板设计注重展示工业设备的专业性和技术特点,帮助企业建立可靠的线上展示平台。查看源码
  • 帝国cms7.5模板生活常识美食女性时尚综合资讯门户源码本模板为帝国cms7.5生活资讯类网站设计,以天奇生活网为参考原型,涵盖生活常识、美食烹饪、女性时尚等多元化内容板块。采用响应式布局设计,适配各种终端设备,为访客提供优质的阅读体验。模板结构清晰合理,内容展示层次分明,符合生活类网站的用户需求。查看源码
  • 自适应html5二极管LED灯具灯饰类企业网网站模板该PbootCMS内核开发的响应式模板专为LED照明、灯具制造类企业设计,通过HTML5技术实现手机与PC端自适应显示,确保跨设备访问体验一致。企业可快速替换图文内容适配其他工业领域查看源码
  • (PC+WAP)化工材料企业环保能源绿色营销型pbootcms模板源码下载本模板为化工材料及环保能源企业设计,采用PbootCMS开发,可展示各类化工产品、环保技术及能源解决方案。查看源码
分享笔记 (共有 篇笔记)
验证码: