jQuery Ajax File Upload实例源码

前端之家收集整理的这篇文章主要介绍了jQuery Ajax File Upload实例源码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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


@H_3010@

项目结构


@H
3010@Default.aspx
Upload.aspx
Scripts/…
style.css


@H
301_0@

效果


<p style="text-align: center">


@H_301_0@

客户端HTML代码


<div class="jb51code">
<pre class="brush: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
      @H_301_0@

      服务端处理代码Upload.aspx

      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"); 
        } 
      } 

      }
      }

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

      猜你在找的Ajax相关文章