zoukankan      html  css  js  c++  java
  • webform ajax 上传文件+参数

    今天维护webform项目时,有个需求需要在一个ajax中上传excel和多个参数。网上没怎么找到答案,这边做个笔记。

    首先上页面大体这样

      <form  id= "uploadForm">
            <input type="file" accept=".xlsx,.xls" name="excel" id="file" />
            <input type="button" id="upload" value="Import" />
        </form>
    

    再是jquery代码

    <script type="text/javascript">
        $(function () {
            $('#upload').click(function () {
                var formData = new FormData($("#uploadForm")[0]);
                formData.append("name", "zhangsan");
                $.ajax({
                    url: 'ImportExcel.aspx',
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType:false,
                    processData: false,
                    success: function (returndata) {
                        alert(returndata);
                    },
                    error: function (returndata) {
                        alert(returndata);
                    }
                });
            });
        })
       

    后台接收简单的方法

    var name = Request["name"];
    
    var file=Request.Files["excel"];

    比较简单,但是长时间不用也容易忘记,这里笔记下,也欢迎高手指正。

  • 相关阅读:
    监控JVM回收
    linux JDK安装
    linux 免登陆设置
    搭建redis集群总结
    redis开启持久化
    搭建redis主从复制,遇到的问题总结
    Redis配置参数说明
    模板模式
    观察者模式
    适配器模式
  • 原文地址:https://www.cnblogs.com/ares-yang/p/7133641.html
Copyright © 2011-2022 走看看