如何在没有回发的情况下使用 JavaScript 上传文件? [英] How can I upload a file using JavaScript without a postback?

查看:36
本文介绍了如何在没有回发的情况下使用 JavaScript 上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 ASP.NET 中的文件上传.我使用了 <input type=file id=upload><input type=button id="btnupload" value="File Upload">

I am working on a file upload in ASP.NET. I used <input type=file id=upload> and <input type=button id="btnupload" value="File Upload">

我想用 JavaScript 上传文件.更新面板不起作用,我不希望它回发并刷新页面.

I want to upload the file in JavaScript. The update panel does not work, I do not want it to postback and refresh the page.

谢谢,但是如果您有与 javascript 中的 fileUpload 相关的代码,请发送给我.请帮我.

thanks but If you have code related to fileUpload in javascript then send me. please help me.

推荐答案

可以使用 jQuery 和 jQuery 表单插件.我在几个项目中使用了这个组合,我没有问题,即使是大文件(10mb)

You can use jQuery and jQuery form plugin. I used this combination for few project and i had no problems, even for big files (10mb)

<form action="form.asp" method="post">
.......
</form>
$('form').submit(function(){
 $(this).ajaxSubmit(function(data){
  $('#updateDiv').html(data); // or append/prepend/whatever
 })
 return false
})

当然,表单的操作会返回您需要更新的内容.您可能需要添加一些额外的函数来处理错误,但这应该可以正常工作

Ofcourse, the action of the form will return what you need to update. You may want to add some extra functions to handle errors, but this should work fine

这篇关于如何在没有回发的情况下使用 JavaScript 上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆