技术文摘

几个小小设置把帝国CMS弹窗alert支持json格式输出

作者:雨祺   发表于:
浏览:98次    字数:4363  原创
级别: 站长   总稿: 69 篇,  月稿: 0
几个小小设置可以把帝国弹窗alert支持json格式输出,原来alert弹窗就不见了,不影响原版功能;
虽然这个功能自己几乎不用 ,看到网友经常要处理这个问题,顺手发一个。
1、在要输出json头部代码
  1. ------------------------------- 
  2. define('API_WORK'true); 
  3. ------------------------------- 
2.改造printerror和printerror2,增加一个参数$statuscode,不写的状态200
  1. //错误提示 
  2. function printerror($error="",$gotourl="",$ecms=0,$noautourl=0,$novar=0, $statuscode = 200){ 
  3.         global $empire,$editor,$public_r,$ecms_config; 
  4.         if($editor==1){$a="../";} 
  5.         elseif($editor==2){$a="../../";} 
  6.         elseif($editor==3){$a="../../../";} 
  7.         else{$a="";} 
  8.         if($ecms==1||$ecms==9) 
  9.         { 
  10.                 $a=ECMS_PATH.'e/data/'
  11.         } 
  12.         if(strstr($gotourl,"(")||empty($gotourl)) 
  13.         { 
  14.                 if(strstr($gotourl,"(-2")) 
  15.                 { 
  16.                         $gotourl_js="history.go(-2)"
  17.                         $gotourl="javascript:history.go(-2)"
  18.                 } 
  19.                 else 
  20.                 { 
  21.                         $gotourl_js="history.go(-1)"
  22.                         $gotourl="javascript:history.go(-1)"
  23.                 } 
  24.         } 
  25.         else 
  26.         {$gotourl_js="self.location.href='$gotourl';";} 
  27.         if(empty($error)) 
  28.         {$error="DbError";} 
  29.         if($ecms==9)//前台弹出对话框 
  30.         { 
  31.                 @include $a.LoadLang("pub/q_message.php"); 
  32.                 $error=empty($novar)?$qmessage_r[$error]:$error; 
  33.                 
  34.                 //修改的
  35.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  36.                 
  37.                 echo"<script>alert('".$error."');".$gotourl_js."</script>"
  38.                 db_close(); 
  39.                 $empire=null
  40.                 exit(); 
  41.         } 
  42.         elseif($ecms==8)//后台弹出对话框 
  43.         { 
  44.                 @include $a.LoadLang("pub/message.php"); 
  45.                 $error=empty($novar)?$message_r[$error]:$error; 
  46.                 
  47.                 //修改的 
  48.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  49.                 
  50.                 echo"<script>alert('".$error."');".$gotourl_js."</script>"
  51.                 db_close(); 
  52.                 $empire=null
  53.                 exit(); 
  54.         } 
  55.         elseif($ecms==7)//前台弹出对话框并关闭窗口 
  56.         { 
  57.                 @include $a.LoadLang("pub/q_message.php"); 
  58.                 $error=empty($novar)?$qmessage_r[$error]:$error; 
  59.                 
  60.                 //修改的 
  61.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  62.                 
  63.                 echo"<script>alert('".$error."');window.close();</script>"
  64.                 db_close(); 
  65.                 $empire=null
  66.                 exit(); 
  67.         } 
  68.         elseif($ecms==6)//后台弹出对话框并关闭窗口 
  69.         { 
  70.                 @include $a.LoadLang("pub/message.php"); 
  71.                 $error=empty($novar)?$message_r[$error]:$error; 
  72.                 echo"<script>alert('".$error."');window.close();</script>"
  73.                 db_close(); 
  74.                 $empire=null
  75.                 exit(); 
  76.         } 
  77.         elseif($ecms==0) 
  78.         { 
  79.                 @include $a.LoadLang("pub/message.php"); 
  80.                 $error=empty($novar)?$message_r[$error]:$error; 
  81.                 
  82.                 //修改的
  83.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  84.                 
  85.                 @include($a."message.php"); 
  86.         } 
  87.         else 
  88.         { 
  89.                 @include $a.LoadLang("pub/q_message.php"); 
  90.                 $error=empty($novar)?$qmessage_r[$error]:$error; 
  91.                 
  92.                 //修改的
  93.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  94.                 
  95.                 @include($a."../message/index.php"); 
  96.         } 
  97.         db_close(); 
  98.         $empire=null
  99.         exit(); 
  1. //错误提示2:直接文字 
  2. function printerror2($error='',$gotourl='',$ecms=0,$noautourl=0, $statuscode = 200){ 
  3.         global $empire,$public_r; 
  4.         if(strstr($gotourl,"(")||empty($gotourl)) 
  5.         { 
  6.                 if(strstr($gotourl,"(-2")) 
  7.                 { 
  8.                         $gotourl_js="history.go(-2)"
  9.                         $gotourl="javascript:history.go(-2)"
  10.                 } 
  11.                 else 
  12.                 { 
  13.                         $gotourl_js="history.go(-1)"
  14.                         $gotourl="javascript:history.go(-1)"
  15.                 } 
  16.         } 
  17.         else 
  18.         {$gotourl_js="self.location.href='$gotourl';";} 
  19.         if($ecms==9)//弹出对话框 
  20.         { 
  21.                 //修改的
  22.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  23.                 
  24.                 echo"<script>alert('".$error."');".$gotourl_js."</script>"
  25.         } 
  26.         elseif($ecms==7)//弹出对话框并关闭窗口 
  27.         { 
  28.                 //修改的
  29.                 if(defined('API_WORK') && API_WORK)        throw new Exception($error, '1' . $statuscode); 
  30.                 
  31.                 echo"<script>alert('".$error."');window.close();</script>"
  32.         } 
  33.         else 
  34.         { 
  35.                 @include(ECMS_PATH.'e/message/index.php'); 
  36.         } 
  37.         db_close(); 
  38.         exit(); 
3、使用自动加载功能和异常处理。以上3个步骤完成,一起来体验吧!
upload.rar
1ef485c66fdec652ee7af98e4c62a441.rar (31.54 KB)

技巧:define('API_WORK', true);可以改为动态的,不是新写的文件时还有必要,传一下$_GET['json'] = 1就样就可以解决了
  1. define('API_WORK', isset($_GET['json'])); 
这个就可以原代码一个不动了

【审核人:站长】

收藏   加好友   生成海报   分享
点赞(0)
打赏
Tags: 帝国CMS 弹窗 帝国

发布者资料

热门文章

技术文摘

查看更多技术文摘
首页
栏目
搜索
会员
投稿