bricks/examples/fileupload.html

65 lines
1.1 KiB
HTML
Raw Normal View History

2023-09-14 10:28:07 +08:00
<html>
<head>
</head>
<body>
<div>
<button onclick="f()">uoload</button>
</div>
<script src="../bricks/bricks.js"></script>
<script>
const opts =
{
"widget": {
"widgettype":"VBox",
"options":{
},
"subwidgets":[
{
"id":"file1",
"widgettype":"UtFile",
"options":{
"name":"file1",
"label":"File 1"
}
},
{
"widgettype":"Text",
"options":{
"text":"upload"
},
"binds":[
{
"wid":"self",
"event":"clcik",
"action":{
"rfname":"do_upload"
}
}
]
}
]
}
}
;
var f = async function(){
console.log('it work');
var b = new Bricks();
var w = b.getWidgetById('file1', bricks_app.root);
var file = w.files[0];
var fd = new FormData();
fd.append('file1', file);
var resp = await jcall('http://192.168.1.10/examples/fileupload.dspy',{
method:'POST',
params:fd
})
console.log('resp=', resp);
}
rf = new RegisterFunction();
rf.register('do_upload', f);
const app = new BricksApp(opts);
app.run();
</script>
</body>
</html>