几个小小设置可以把帝国弹窗alert支持json格式输出,原来alert弹窗就不见了,不影响原版功能;
虽然这个功能自己不会用 ,看到网友经常要处理这个问题,顺手发一个。
http://bbs.phome.net/showthread-42-366066-0.html 像这个问题也可以这里解决的
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个步骤完成,一起来体验吧
最新更新v1.0.5版 http://bbs.phome.net/ShowThread/?threadid=366088&forumid=13&page=2#ret1286876
上传以下附件: [下载 *.zip](文件大小:31.58 KB,下载次数:17)
|