From 57d741653a56175e29d41cbc073254edb68c8d4e Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 17 Oct 2023 10:42:38 +0800 Subject: [PATCH] add some --- lib/misc.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/misc.js b/lib/misc.js index 09bb9c2c..214151db 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -92,9 +92,15 @@ Volcanos("misc", { var data = can.core.ItemForm(form, function(v, i, k) { return k+mdb.EQ+encodeURIComponent(v) }).join("&") if (can.base.isIn(msg._method, http.GET, http.DELETE)) { url += (url.indexOf("?") == -1? "?": "&")+data, data = "" } xhr.open(msg._method||http.POST, url), xhr.onreadystatechange = function() { if (xhr.readyState != 4) { return } - try { var res = JSON.parse(xhr.responseText) } catch (e) { var res = {result: [xhr.responseText]} } msg.Option("_cost", new Date() - begin) + try { var res = JSON.parse(xhr.responseText) } catch (e) { + if (xhr.responseText.indexOf("warn: ")) { + var res = {result: [xhr.responseText]} + } else { + var res = {result: [xhr.responseText]} + } + } msg.Option("_cost", new Date() - begin) if (xhr.status == 200) { return msg.detail || (msg.detail = res.detail), can.base.isFunc(cb) && cb(msg.Copy(res)) } - can.user.toastFailure(can, xhr.response, url), can.misc.Warn(xhr.status, res, url, form) + can.user.toastFailure(msg._can||can, xhr.response), can.misc.Warn(xhr.status, res, url, form) cbs && cbs(xhr) }, xhr.setRequestHeader(http.Accept, msg._accept||http.ApplicationJSON) if (msg._upload) { var data = new FormData(); can.core.ItemForm(form, function(v, i, k) { data.append(k, v) })