小编Ser*_*hts的帖子

在表单提交/节点之后阻止页面重新加载(没有可用的ajax)

美好的一天,我有一个表单,用于将字段和文件发送到node.js服务器.在服务器上由Formidable解析的数据.一切都运行良好,但在表单提交后,它会加载一个带有响应的页面.有没有人知道使用标准表单机制发送数据的方式不是重新加载页面(带有serialize的jQuery ajax方法因为表单中文件而无法工作)要么在服务器上写这样的响应,所以它不会触发页面重新加载.形成:

<form action="/upload" enctype="multipart/form-data" method="post" id="eventForm">
<label>Date</label>
<input type="text" name="date"/>
<label>Image</label>
<input type="file" multiple="multiple" name="picture" />
<input type="submit" value="Submit!" />
</form>
Run Code Online (Sandbox Code Playgroud)

服务器端:

app.post('/upload', function (req, res) {
    var form = new formidable.IncomingForm();
    // save file code goes here 
    form.parse(req, function(err, fields, files) {
        //response code goes here
        res.send('done');
    });
});
Run Code Online (Sandbox Code Playgroud)

有更好的方法吗?谢谢!

javascript forms ajax node.js formidable

2
推荐指数
1
解决办法
9963
查看次数

标签 统计

ajax ×1

formidable ×1

forms ×1

javascript ×1

node.js ×1