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>

  • 相关阅读:
    Multidimensional Arrays
    TortoiseGit
    Excel教程(14)
    Excel教程(13)
    Excel教程(12)
    Excel教程(11)
    lock
    reflect
    game
    html x
  • 原文地址:https://www.cnblogs.com/M87-A/p/12860153.html
Copyright © 2011-2022 走看看