index.html 1.09 KB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>action is everything</title>
</head>
<body>
<div  data-th-fragment="header">
    <h1> 图片q </h1>
</div>
<form>
    <input type="file"  id="file" name="file">
    <button type="button"  onclick="submitForm()">提交</button>

</form>
</body>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
    function submitForm() {
        var formData = new FormData(); //将需要提交的参数封装起来
        formData.append("file", $("#file")[0].files[0]);
        $.ajax({
            //url:'upload',
            url : 'http://121.40.109.21:8083/file-center/file/fileUpload',
            beforeSend: function(xhr) {
                xhr.setRequestHeader("ossPath","test");
            },
            type : 'post',
            data : formData,
            processData : false,
            contentType : false,
            success : function(value) {
               alert(value);
            },
            error:function (value) {
                alert(value);
            }
        });

    }
</script>
</html>