zoukankan      html  css  js  c++  java
  • ajax提交form表单

    由于语言和场景不一样,网上的资料并不一定完美解决自己的问题。

    参考链接:http://yunzhu.iteye.com/blog/2177923

    花了点时间解决这个问题,在次记录一下。

    Jq+asp.net 提交form表单。

    Html+JS代码:

     1     @******************************************************************************************************************@
     2     <form style="border:dashed" action="../News/TestForm" method="post" enctype="multipart/form-data" id="fromData">
     3         <div>
     4             <label>填写</label><input type="text" name="text" />
     5             <textarea name="textarea"></textarea>
     6 
     7             <input type="file" name="uploadfile" />
     8 
     9             <input type="button" name="submit11" id="submit11" value="提交" />
    10         </div>
    11     </form>
    12     <script src="~/js/jquery.min.js"></script>
    13     <script src="~/js/jquery.form.js"></script>
    14     <script type="text/javascript">
    15         $("#submit11").click(function () {
    16             var formData = new FormData(document.getElementById("fromData"));
    17             $.ajax({
    18                 type: "post",
    19                 cache: true,
    20                 url: "../News/TestForm",
    21                 data: formData,
    22                 contentType: false,           //一定要加这两行,不然报错Illegal invocation
    23                 processData: false,           //一定要加这两行,不然报错Illegal invocation
    24                 success: function (data) {
    25                     alert(data);
    26                 }
    27             })
    28         });
    29     </script>
    30     @******************************************************************************************************************@

    控制器代码:

    1         public string TestForm(FormCollection form)
    2         {
    3             string text = form["text"];
    4             string textarea = form["textarea"];
    5             HttpPostedFileBase file = Request.Files["uploadfile"];
    6             string result = "YES";
    7             return result;
    8         }
  • 相关阅读:
    vue2.0实践的一些细节
    数据库之一
    angularJS实用的开发技巧
    移动端开发的一些技巧总结(2)
    vue入门学习(基础篇)
    JS继承之原型继承
    css3动画
    使用 xlsx 前端解析 excel 文件
    webpack4 打包 library 遇到的坑
    roc-charts 开发笔记:JS广度优先查找无向无权图两点间最短路径
  • 原文地址:https://www.cnblogs.com/yuan-jiang/p/8268749.html
Copyright © 2011-2022 走看看