使用局jQuery提交file

原创
2017/12/25 15:03
阅读数 49
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="file" name="addressBook" id="addressBook">
    <input type="button" value="上传" id="gogo"/>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script>
 jQuery("#gogo").on('click',function() {
     console.log("^^^^^^^^^^^^^^^^^^^^^^^^^");
     console.log($("#addressBook"));
     console.log($("#addressBook")[0].files);
     var formData = new FormData();
     formData.append('addressBook', jQuery("#addressBook")[0].files[0]);
     jQuery.ajax({
         url: "http://127.0.0.1:5000/web/group/upload/",
         type: "POST",
         data: formData,
         dataType: "json",
         cache : false,
         processData: false,
         contentType: false,
         success: function (data) {
             console.log(data);
         },
         error: function (XMLHttpRequest, textStatus, errorThrown) {
             console.log(XMLHttpRequest.status);
         }
     });
 });
 </script>
</body>
</html>

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部