jQuery Ajax File Upload实例源码

本文实例为大家分享了jQuery Ajax File Upload实例源码,供大家参考,具体内容如下

项目结构

Default.aspx Upload.aspx Scripts/… style.css

效果

客户端HTML代码

rush:xhtml;"> <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UploadFile.aspx.vb" Inherits="Web.UploadFile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">

Box name: 'uploadfile',onSubmit: function (file,ext) { if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) { // check for valid file extension status.text('Only JPG,PNG or GIF files are allowed'); return false; } status.text('Uploading...'); },onComplete: function (file,response) { //On completion clear the status status.text(''); //Add uploaded file to list if (response === "success") { $('
  • ').appendTo('#files').html('
    ' + file).addClass('success'); } else { $('
  • ').appendTo('#files').text(file).addClass('error'); } } }); });

    // --></mce:script>

    Upload File

      服务端处理代码Upload.aspx

      rush:csharp;"> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;

      namespace JqueryAjaxUploadTest
      {
      public partial class Upload : System.Web.UI.Page
      {
      protected void Page_Load(object sender,EventArgs e)
      {
      try
      {
      HttpPostedFile hpfFile = Request.Files["uploadfile"];
      hpfFile.SaveAs(Server.MapPath("~/uploads/") + hpfFile.FileName);
      Response.Write("success");
      }
      catch (Exception)
      {

          Response.Write("fail"); 
        } 
      } 

      }
      }

      以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

      相关文章

      IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
      PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
      使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
      Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
      本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
      Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...