博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery Ajax File Upload(附源码)
阅读量:4459 次
发布时间:2019-06-08

本文共 1621 字,大约阅读时间需要 5 分钟。

项目结构

Default.aspx

Upload.aspx
Scripts/…
style.css

效果图

客户端html代码

隐藏行号 复制代码 Default.aspx
  1. <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UploadFile.aspx.vb" Inherits="Web.UploadFile" %>
  2.  
  3.  
  4.  
  5.  
  6. $(function () {
  7. var btnUpload = $('#upload');
  8. var status = $('#status');
  9. new AjaxUpload(btnUpload, {
  10. action: 'Upload.aspx',
  11. //Name of the file input box
  12. name: 'uploadfile',
  13. onSubmit: function (file, ext) {
  14. if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
  15. // check for valid file extension
  16. status.text('Only JPG, PNG or GIF files are allowed');
  17. return false;
  18. }
  19. status.text('Uploading...');
  20. },
  21. onComplete: function (file, response) {
  22. //On completion clear the status
  23. status.text('');
  24. //Add uploaded file to list
  25. if (response === "success") {
  26. $('
  27. ').appendTo('#files').html('
    ' + file).addClass('success');
  28. } else {
  29. $('
  30. ').appendTo('#files').text(file).addClass('error');
  31. }
  32. }
  33. });
  34. });
  35.  
  36.  
  37.  
  38.  
  39. Upload File
  40.  
  41.  
  42. Upload File
    •  
    •  
    •  
    •  
    •  
    •  

    服务端处理代码Upload.aspx

    隐藏行号 复制代码 Default.aspx
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using System.Web.UI;
    6. using System.Web.UI.WebControls;
    7.  
    8. namespace JqueryAjaxUploadTest
    9. {
    10. public partial class Upload : System.Web.UI.Page
    11. {
    12. protected void Page_Load(object sender, EventArgs e)
    13. {
    14. try
    15. {
    16. HttpPostedFile hpfFile = Request.Files["uploadfile"];
    17. hpfFile.SaveAs(Server.MapPath("~/uploads/") + hpfFile.FileName);
    18. Response.Write("success");
    19. }
    20. catch (Exception)
    21. {
    22.  
    23. Response.Write("fail");
    24. }
    25. }
    26. }
    27. }

    下载地址:

    找到文件 jquery ajax file upload(刚刚上传,文件可能还没刷出来)

    转载于:https://www.cnblogs.com/psunny/archive/2010/10/21/1857326.html

    你可能感兴趣的文章
    centos7 update network time
    查看>>
    装饰模式
    查看>>
    苹果新的编程语言 Swift 语言进阶(十一)--实例的初始化与类的析构
    查看>>
    node.js整理 03文件操作-遍历目录和文本编码
    查看>>
    mysql字段累加concat
    查看>>
    TCP协议的三次握手和四次挥手过程
    查看>>
    linux内核中有哪些子系统(框架)呢?
    查看>>
    python built-in zip()
    查看>>
    Android AsynTask更新主界面
    查看>>
    yii使用CUploadedFile上传文件
    查看>>
    《redis-php中文参考手册》
    查看>>
    System.IO.File.Create 不会自动释放,一定要Dispose
    查看>>
    【LeetCode】【找元素】Find First and Last Position of Element in Sorted Array
    查看>>
    PHP--y2k38的解决方法已经时间格式的常用转换
    查看>>
    vue环境搭建及简单接触
    查看>>
    #113. 【UER #2】手机的生产
    查看>>
    [算法导论 12章] 二叉查找树
    查看>>
    多线程简单实例(3)线程池
    查看>>
    hive函数总结
    查看>>
    WPF 中如何使得DataGrid的Column有鼠标点击相应
    查看>>