mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
add ajax png
This commit is contained in:
parent
1e0dbde61b
commit
3e0797251f
14
lib/misc.js
14
lib/misc.js
@ -3,10 +3,21 @@ Volcanos("misc", {help: "工具模块",
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", url), xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) {return}
|
||||
|
||||
switch (xhr.getResponseHeader("content-type")) {
|
||||
case "image/png":
|
||||
if (xhr.responseType != "blob") {
|
||||
msg.responseType = "blob"
|
||||
can.misc.POST(can, msg, url, form, cb)
|
||||
return
|
||||
}
|
||||
break
|
||||
default:
|
||||
try { // 解析响应
|
||||
var res = JSON.parse(xhr.responseText);
|
||||
} catch (e) {
|
||||
var res = {"result": [xhr.responseText]}
|
||||
var res = {"result": []}
|
||||
}
|
||||
}
|
||||
xhr.status == 200 && typeof cb == "function" && cb(msg.Copy(res));
|
||||
}
|
||||
@ -32,6 +43,7 @@ Volcanos("misc", {help: "工具模块",
|
||||
// 发送请求
|
||||
++arguments.callee.meta.order
|
||||
xhr.setRequestHeader("Accept", "application/json")
|
||||
xhr.responseType = msg.responseType || ""
|
||||
xhr.send(data)
|
||||
msg._xhr = xhr
|
||||
}),
|
||||
|
@ -62,7 +62,9 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
Volcanos("onaction", {help: "组件交互", list: [
|
||||
["layout"].concat(Config.layout.list), "清屏", "刷新", "并行","串行",
|
||||
["action", "正常", "竖排", "编排", "定位", "定形"],
|
||||
{input: "pod"}, {input: "you"}, {input: "hot"}, {input: "top"},
|
||||
{input: "pod"}, {input: "you"},
|
||||
{input: "hot"}, {input: "top"},
|
||||
{input: "grp"}, {input: "lab"},
|
||||
],
|
||||
layout: function(event, can, value, cmd, field) {can.Export(event, cmd, value)},
|
||||
|
||||
|
@ -29,8 +29,19 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
}
|
||||
})
|
||||
} else {
|
||||
switch (msg._xhr.getResponseHeader("content-type")) {
|
||||
case "image/png":
|
||||
if (msg._xhr.responseType != "blob") {
|
||||
break
|
||||
}
|
||||
var str = URL.createObjectURL(new Blob([msg._xhr.response], {type: "image/png"}));
|
||||
msg.result && can.page.Append(can, output, [{img: [str]}])
|
||||
break
|
||||
|
||||
default:
|
||||
msg.result && can.page.Append(can, output, [{view: ["code", "div", can.page.Display(msg.Result())]}]).code;
|
||||
}
|
||||
}
|
||||
return typeof cb == "function" && cb(msg);
|
||||
},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user