zoukankan      html  css  js  c++  java
  • jquery文件表单上传

    1. 引入jquery文件  <script src="js/jquery-2.1.1.min.js"></script>

    2. 创建form表单,如下:

    <form enctype="multipart/form-data" id="form">
    <p><label>name:</label><input type="text" name="name"/></p>
    <p><label>文件:</label><input type="file" name="fileName" /></p>
    <p><input type="button" value="提交" id="submit"/></p>
    </form>

    3.js提交部分:

    <script type="text/javascript">
      $(document).ready(function () {
        var fd = new FormData(document.getElementById("form"));
        $.ajax({
          url:"my_url",
          type:"post", 
          data:fd,
          contentType:false, // 不允许修改请求头内容
          processData:false,
          async:false,
          success:function(result){
            console.log(result);
          },
          //请求失败,包含具体的错误信息
          error : function(e){
            console.log(e.status);
            console.log(e.responseText);
          }
        });
      });
    </script>

  • 相关阅读:
    Power of Cryptography
    Radar Installation
    Emag eht htiw Em Pleh
    Help Me with the Game
    89. Gray Code
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
    84. Largest Rectangle in Histogram
    82. Remove Duplicates from Sorted List II
  • 原文地址:https://www.cnblogs.com/M87-A/p/12860153.html
Copyright © 2011-2022 走看看