您现在的位置是:首页 > 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系统开发,专为重型机械设备行业设计,特别适合挖掘机、采矿设备、工程机械等工业设备展示。采用响应式布局技术,确保各类设备参数和图片在不同终端上都能清晰展示。查看源码
  • 自适应LED照明外贸灯具灯泡灯具英文网站模板该外贸灯具网站模板专为LED照明、灯具出口企业定制,采用PbootCMS内核开发,提供高效建站方案。通过响应式设计和SEO优化能力,帮助企业低成本构建专业外贸展示平台。查看源码
  • (自适应手机端)锁锁芯锁具网站pbootcms模板 智能防盗锁网站源码下载本模板基于PbootCMS系统开发,为智能锁具、防盗锁芯及相关安防产品企业设计。采用响应式布局技术,确保在手机、平板和电脑等不同设备上都能获得良好的浏览体验,数据实时同步更新。查看源码
  • (PC+WAP)安保服务保安保镖模板免费下载本模板基于PbootCMS内核开发,为安保服务企业量身打造。设计风格严谨专业,突出安保行业的安全、可靠特性,展示企业服务项目与实力。采用响应式设计,PC与移动端数据同步,管理便捷。模板布局合理查看源码
  • (PC+WAP)绿色产品环保设备垃圾桶厂家公司网站pbootcms模板为垃圾桶生产商、环保设备企业打造的高端响应式门户模板,基于PbootCMS开源内核深度开发。采用HTML5自适应架构,无缝实现PC与手机端数据实时同步与交互优化查看源码
分享笔记 (共有 篇笔记)
验证码: