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) {
                            // 根据返回结果指定界面操作
                        }
                    });
                });
  • 相关阅读:
    DAY 179 在Flask中使用MongoDB:Flask-MongoEngine
    DAY 178 oracle基础
    DAY 177 mongoengine
    DAY 176 redis教程
    存储器
    cpu
    java 类文件类型
    线程池
    CopyOnWrite容器
    ConcurrentHashMap
  • 原文地址:https://www.cnblogs.com/enych/p/8403580.html
Copyright © 2011-2022 走看看