如何在没有回发的情况下使用 JavaScript 上传文件?

1

本文介绍了如何在没有回发的情况下使用 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 上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

函数委托与函数
Func Delegate vs Function(函数委托与函数)...
2023-11-11 C#/.NET开发问题
6

针对委托检查 MethodInfo
Checking a MethodInfo against a delegate(针对委托检查 MethodInfo)...
2023-11-11 C#/.NET开发问题
7

如何从 lambda 表达式中获取引用实例的实例
How to get the instance of a referred instance from a lambda expression(如何从 lambda 表达式中获取引用实例的实例)...
2023-11-11 C#/.NET开发问题
4

如何为具有空目标的实例方法创建委托?
How to create a delegate to an instance method with a null target?(如何为具有空目标的实例方法创建委托?)...
2023-11-11 C#/.NET开发问题
6