• js+ajax实现多张图片上传


    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>jq+ajax 实现多张图片上传</title>
    </head>
    
    <body>
      <div class="item">
        <input type="file" name="files" id="file" multiple="multiple" accept="image/png,image/jpg,image/gif,image/JPEG">
      </div>
      
      <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <script>
        $('#file').on("change", function () {
          var formData = new FormData();
          for (var i = 0; i < $("#file")[0].files.length; i++) {  //循环获取上传个文件
            formData.append("file", $("#file")[0].files[i]);
          }
          $.ajax({
            "url": "", // 上传地址
            "data": formData,
            "dataType": "json",
            "type": "post",
            "contentType": false, //上传文件一定要是false
            "processData": false,
            "success": function (obj) {
              if (obj.state == 1) {
                console.log(obj)
              } else {
                console.log(obj.message)
              }
            }
          });
        })
      </script>
    </body>
    
    </html>
  • 相关阅读:
    软件测试课堂练习
    JSP第一次作业
    安卓第六次作业
    安卓第五次作业
    第四次安卓作业
    JSP第四周
    软件测试课堂练习3.4
    Android数据库表
    Android购物菜单
    Android增删改查
  • 原文地址:https://www.cnblogs.com/dswg/p/14422521.html
Copyright © 2020-2023  润新知