解决AJAX提交404错误:a padding to disable MSIE and Chrome friendly error page

html 复制代码
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!--用于禁用MSIE和Chrome友好错误页的填充 -->

异常说明

  1. 使用wangEditor编辑器,提交内容;
  2. 正常数据的文本,正常提交;
  3. 外网使用时,上传图片或视频后,出现404页面,具体提示信息:a padding to disable MSIE and Chrome friendly error page
  4. 内网使用时,正常;

异常排查

  • 把所有精力放在解决"a padding to disable MSIE and Chrome friendly error page"是个错误,导致对NGINX的配置、内网外网都进行过怀疑和调试;
  • 尤其是内网可用,外网不可用,更是导致跑了很多远路;
  • 其实,问题的关键在于上传图片后,正常的路由无法获取,就代表网络层被阻断了
  • 逐行调试,对代码转义后,一切正常。

解决方案

转义函数

javascript 复制代码
/*HTML代码转义*/
function escapeHtml(unsafe) {
    return unsafe
        .replace(/&/g, "&amp;")
        .replace(/</g, "&lt;")
        .replace(/>/g, "&gt;")
        .replace(/"/g, "&quot;")
        .replace(/'/g, "&#039;");
}

字段调用

javascript 复制代码
   $.ajax({
                type: "post",
                url: "?m=Forum&a=forumDeal&act=add",
                async: true,
                data: {
                    section: $('#sect_name').val(),
                    forum_title: $('#forum_title').val(),
                    forum_abstract: $('#forum_abstract').val(),
                    forum_age: $('#forum_age').val(),
                    forum_sex: $('#forum_sex').val(),
                    forum_chief: $('#forum_chief').val(),
                    forum_subjective: escapeHtml(forum_subjective),
                    forum_objective: escapeHtml(forum_objective),
                    forum_assess: escapeHtml(forum_assess),
                    forum_treat: escapeHtml(forum_treat),
                    forum_effect: $('#forum_effect').val(),
                    forum_evaluate: escapeHtml(forum_evaluate)
                },
                dataType: "json",
                success: function (res) {
                    //console.log(res);
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 2, time: 2000});
                    } else {
                        layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                            window.parent.location.href = "?m=My&a=myForum";
                        });
                    }
                }, error: function (err) {
                    console.log(err)
                }
            });

入库转义

php 复制代码
        $forum_age = html_entity_decode($_POST['forum_age']);
        $forum_sex = html_entity_decode($_POST['forum_sex']);
        $forum_subjective = html_entity_decode($_POST['forum_subjective']);
        $forum_chief = html_entity_decode($_POST['forum_chief']);
        $forum_objective = html_entity_decode($_POST['forum_objective']);
        $forum_assess = html_entity_decode($_POST['forum_assess']);
        $forum_treat = html_entity_decode($_POST['forum_treat']);
        $forum_effect = html_entity_decode($_POST['forum_effect']);
        $forum_evaluate = html_entity_decode($_POST['forum_evaluate']);

@漏刻有时

相关推荐
三十而立洋2 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
卡布鲁2 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
李少兄2 天前
JavaScript 隐式全局变量解析
javascript
沙蒿同学2 天前
我用 Go 搭了一条 AI Agent 流水线:从 1 张商品图到一整套淘宝详情页
前端·javascript·后端
paopaokaka_luck2 天前
智慧社区综合服务小程序(人脸识别、AI问答、Echarts图形化分析)
前端·javascript·spring boot·spring·数据分析·echarts
Hilaku2 天前
为什么死磕 1px 的团队,用户体验反而更差?
前端·javascript·程序员
陈拉斯2 天前
给公司年会写了个大屏抽奖系统:动画在前端跑,凭什么说结果没被改?
javascript
yzy852 天前
Vue中下载或打开文件的JavaScript方法
前端·javascript·vue
用户298698530142 天前
在 React 中用 JavaScript 将 Word 转换为文本
前端·javascript·react.js
李少兄2 天前
深入解析 JavaScript 中的 `document` 对象
javascript