最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net使用H5新特性實(shí)現(xiàn)異步上傳的示例

 更新時(shí)間:2018年01月15日 15:24:36   作者:一艷傾華  
下面小編就為大家分享一篇asp.net使用H5新特性實(shí)現(xiàn)異步上傳的示例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

###index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <script src="Script/jquery-1.10.2.min.js"></script>
  <script src="Script/index.js"></script>
  <title></title>
  <script type="text/javascript">
    $(function(){
      $("#ajaxFileUpload").click(function () {
        formDataUpload();
      });
    });
  </script>
</head>
<body>
  <input type="file" id="FileToUpload" multiple="multiple" mame="FileToUpload" />
  <input type="button" id="ajaxFileUpload" value="上傳"/>
  <input type="text" size="10"/>
</body>
</html>


###index.js

function formDataUpload() {
  //這里可以一次性選中多個(gè)文件
  var fileUpload = document.getElementById("FileToUpload").files;
  if (fileUpload.length == 0) {
    alert("請選中文件再上傳");
    return;
  }
  //html5新特性
  var formdata = new FormData();
  //添加上傳數(shù)據(jù)
  for (var i = 0; i < fileUpload.length;i++){
    formdata.append('files', fileUpload[i]);
  }

  //使用javascript的原生ajax
  var xmlHttp = new XMLHttpRequest();
  xmlHttp.open("post", 'Handler.ashx?method=formDataUpload');
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      alert("上傳成功");
    }
  }
  xmlHttp.send(formdata);
}

###handler.ashx

<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
    
  public void ProcessRequest (HttpContext context) {
    formDataUpload(context);
  }
  public static void formDataUpload(HttpContext context) {
    //獲取到客戶端提交的文件
    HttpFileCollection files = context.Request.Files;
    string msg = string.Empty;
    string error = string.Empty;
    int fileM = 0;
    if (files.Count > 0) {
      for (int i = 0; i < files.Count; i++) {      ;
        String path = @"D:\"+files[i].FileName;
        files[i].SaveAs(path);
        fileM += files[i].ContentLength;
      }
      msg = "上傳成功,文件總大小:" + fileM;
      string res = "{error :'" + error + "',msg:'" + msg + "'}";
      context.Response.Write(res);
      context.Response.End();
    }
  }
  public bool IsReusable {
    get {
      return false;
    }
  }
}

以上這篇asp.net使用H5新特性實(shí)現(xiàn)異步上傳的示例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

蓝山县| 奉新县| 内丘县| 大渡口区| 龙海市| 巴南区| 潼南县| 洱源县| 黔南| 恭城| 凌海市| 丽江市| 衡南县| 南召县| 亳州市| 沿河| 河北省| 浠水县| 三明市| 庆阳市| 潼南县| 凤庆县| 武清区| 无锡市| 翁牛特旗| 兴城市| 巴塘县| 安达市| 淮安市| 阜南县| 汪清县| 贵阳市| 美姑县| 邹平县| 凤阳县| 澳门| 沙湾县| 铜鼓县| 启东市| 瑞丽市| 崇信县|