美文网首页
jquery 文件上传

jquery 文件上传

作者: 路尔轩 | 来源:发表于2019-10-17 15:21 被阅读0次
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <input type="file" name="upload" id="upload" value="" />
            <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
            <script type="text/javascript">
                let formData = new FormData()
                formData.append('file', $('#upload')[0].files[0])
                $.ajax({
                  url: 'http://lr.offdin.com/v1/upload_photo',
                  type: 'post',
                  data: formData,
                  contentType: false, // 发送数据到服务器时所使用的内容类型。默认是:"application/x-www-form-urlencoded"。 不设置内容类型
                  processData: false, // 布尔值,规定通过请求发送的数据是否转换为查询字符串。默认是 true。 不处理数据
                  success: function (res) {
                    console.log(res)
                  }
                })
            </script>
        </body>
    </html>
    

    相关文章

      网友评论

          本文标题:jquery 文件上传

          本文链接:https://www.haomeiwen.com/subject/yptlyctx.html