ares-yang

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"];

 

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

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2022-01-13
  • 2021-12-28
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案