zoukankan      html  css  js  c++  java
  • html formData 数据 提交和 .netMVC接收


    <form id="uploadForm" enctype="multipart/form-data"> <input type="text" value="0000000000" name="T1" /> <input type="text" value="1111111111" name="T2" /> <input id="file" type="file" name="file" /> <button id="upload" type="button">upload</button> </form>
      $("#upload").click(function () {
                    console.log("123");
                    var formData = new FormData($("#uploadForm")[0]); 
                    console.log(formData.values());
                    $.ajax({
                        url: 'http://localhost:8563/Phone/PhonePersonInformation/test',
                        type: 'POST',
                        cache: false,
                        data: formData,
                        processData: false,
                        contentType: false
                    }).done(function (res) {
                        console.log(res);
                    }).fail(function (res) {
                        console.log("222222");
                    });
                });
      public ActionResult test(student mode) 
            {
                if (Request.Files.Count == 0)
                {
                    //throw new Exception("请选择上传文件!");
                }
                for (int i = 0; i < Request.Files.Count; ++i)
                {
                    HttpPostedFileBase file = Request.Files[i];
                    // 文件名为空证明没有选择上传文件
                    if (file.FileName == "")
                    {
                        return Content("文件名空");
                    }
                }
                return Content("接收成功");
            }
            public class student
            {
                public string T1 { get; set; }
                public string T2 { get; set; }
            }

        <form id="uploadForm" enctype="multipart/form-data">
            <input type="text" value="0000000000" name="T1" />
            <input type="text" value="1111111111" name="T2" />
            <input id="file" type="file" name="file" />
            <button id="upload" type="button">upload</button>
        </form>
    $("#file").on("change", function () {
                    var formData = new FormData();
                    formData.append("s1", $("#file")[0].files);
                    formData.append("Key1", "00000");
                    formData.append("Key2", $("#uploadForm").serialize());
                    for (var value of formData.values()) {
                        console.log(value);
                    }
                    console.log(formData.get("Key1"));
                    console.log(formData.get("Key2"));
                    $.ajax({
                        url: "http://localhost:8563/Phone/PhonePersonInformation/test",
                        type: "POST",
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function (response) {
                            // 根据返回结果指定界面操作
                        }
                    });
                });
  • 相关阅读:
    二分查找法
    Three-way Partition
    百面机器学习读书笔记
    天才在左,疯子在右
    Coach Shane's Daily English Dictaion 6-10
    Coach Shane's Daily English Dictation 1-5
    国外有意思的网站
    docker操作指南
    创建docker本地仓库的步骤
    tensorflow去掉warning的方法
  • 原文地址:https://www.cnblogs.com/enych/p/8403580.html
Copyright © 2011-2022 走看看