<%--
  Created by IntelliJ IDEA.
  User: ZJW
  Date: 2019/8/3
  Time: 23:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="post" action="#" id="uploadForm" enctype="multipart/form-data">
    上传新头像：<input type="file" name="userPic"><br>
    <input type="button" id="uploadBtn" value="提交"><br>
</form>

</body>
<script  src="https://dsada1.oss-cn-beijing.aliyuncs.com/js/jquery-3.3.1.min.js"></script>
    <script>
        $("#uploadBtn").click(function () {
            /**
             * $("#uploadForm") 是一个JQuery对象
             * $("#uploadForm")[0] 将JQuery对象转成DOM元素
             * @type {FormData}
             */
            var formData = new FormData($("#uploadForm")[0])
            $.ajax({
                url:"/perPictUploadFile.action",
                type:"POST",
                data:formData,
                async:false,
                cache:false,
                contentType:false,
                processData:false,
                success:function (data) {
                    console.log(data);
                },
                error:function (error) {
                    console.log("error:"+error);
                }
            })
        })
    </script>
</html>
