Merge pull request 'fix(forum): hard-fail delete-draft AJAX when server returns HTML' (#203) from fix/forum-delete-draft-ajax-feedback into main
Reviewed-on: CYL/wordpress-theme-aksrt#203
This commit is contained in:
commit
73de3ffead
1 file changed
+29
-3
@@ -1115,12 +1115,38 @@
|
|||||||
data.append('draft_id', draftId);
|
data.append('draft_id', draftId);
|
||||||
|
|
||||||
fetch(ajaxUrl, { method: 'POST', body: data, credentials: 'same-origin' })
|
fetch(ajaxUrl, { method: 'POST', body: data, credentials: 'same-origin' })
|
||||||
.then(function (r) { return r.json(); })
|
.then(function (r) {
|
||||||
.then(function (payload) {
|
return r.text().then(function (text) {
|
||||||
if (payload.success) {
|
var payload = null;
|
||||||
|
try {
|
||||||
|
payload = text ? JSON.parse(text) : null;
|
||||||
|
} catch (e) {
|
||||||
|
payload = null;
|
||||||
|
}
|
||||||
|
return { ok: r.ok, status: r.status, payload: payload, raw: text };
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(function (res) {
|
||||||
|
if (res.payload && res.payload.success) {
|
||||||
var item = btn.closest('.aksrt-forum-compose__draft-item');
|
var item = btn.closest('.aksrt-forum-compose__draft-item');
|
||||||
if (item) item.remove();
|
if (item) item.remove();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
var msg = (res.payload && res.payload.data && res.payload.data.message)
|
||||||
|
|| (res.payload && res.payload.message)
|
||||||
|
|| (res.status === 500
|
||||||
|
? '服务器错误:请确认主题已更新到最新 main(Forum.php 草稿 autoload 修复)'
|
||||||
|
: '删除失败');
|
||||||
|
if (window.console && console.warn) {
|
||||||
|
console.warn('[aksrt] delete draft failed', res.status, msg);
|
||||||
|
}
|
||||||
|
window.alert(msg);
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
if (window.console && console.warn) {
|
||||||
|
console.warn('[aksrt] delete draft network error', err);
|
||||||
|
}
|
||||||
|
window.alert('删除失败,请稍后重试');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user