var title = (fd.get('title') || '').trim(); var content = (fd.get('content') || '').trim(); if (mode === 'request') { if (!title) { setMsg('片名不能为空~', true); return; } // 求片内容可以为空(只补充说明) } else { // 留言必须有内容 if (!content) { setMsg('留言内容不能为空~', true); return; } } setMsg('提交中...', false); var url = "/index/feedback/save.html"; // 保持你原来的路由写法 fetch(url, { method: 'POST', body: fd, credentials: 'same-origin' }).then(function(res){ return res.json().catch(function(){ return {code: 0, msg: 'ok'}; // 没 JSON 也当成功 }); }).then(function(data){ if (data.code === 0) { // 约定:0 = 成功 setMsg('已提交,我们会尽量处理~', false); form.reset(); applyMode(mode); // 重置占位/文案 } else { setMsg(data.msg || '提交失败,请稍后重试', true); } }).catch(function(){ setMsg('网络异常,稍后再试试~', true); }); }); })();