How can I upload a file using JavaScript without a postback?(如何在没有回发的情况下使用 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 上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在没有回发的情况下使用 JavaScript 上传文件
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
