您现在的位置是:首页 > 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源码下载这是一款针对智能安防行业特点设计的网站模板,采用蓝色系配色方案,体现科技感和安全性。模板包含产品展示、解决方案、技术支持和新闻中心等核心模块,能够全面展示智能安防设备的技术特点和行业应用。查看源码
  • (自适应)英文外贸电子设备网站模板三级子目录基于PbootCMS内核开发的响应式英文网站模板,为外贸企业打造,支持多行业快速适配。通过简洁高效的代码架构,帮助企业低成本构建专业海外形象,实现更好客户触达与订单转化。查看源码
  • (自适应)电子元件电路板元器件pbootcms网站源码下载为电子元器件、电路板制造类企业设计,特别适合展示产品参数、技术规格等内容。采用响应式技术,确保各类电子元件在不同设备上都能清晰展示。查看源码
  • (PC+WAP)蓝色新能源环保太阳能光伏模板pbootcms下载新能源环保行业网站解决方案为太阳能光伏系统企业打造的专业网站模板,助力新能源企业高效展示产品与服务PbootCMS内核开发,源码开放可修改PC与手机端自适应设计查看源码
  • (PC+WAP)绿色环保建筑设备通用行业pbootcms源码下载通过模块调整可适配园林景观、装配式建筑、绿色装修等生态建设相关领域。预制绿色建材展示、能耗模拟等专业模块,集成项目案例、环保工艺等建筑行业特色内容结构,测试数据包含LEED认证体系查看源码
  • (自适应响应式)蓝色勘察设计院机构单位商会协会pbootcms模板下载本模板基于PbootCMS系统开发,为勘察设计院所、工程咨询单位设计,特别适合展示设计成果、技术服务和项目案例。采用响应式技术,确保设计图纸和方案以及文案在不同设备上都能清晰展示。查看源码
分享笔记 (共有 篇笔记)
验证码: