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 上传文件
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01