zoukankan      html  css  js  c++  java
  • 上传input中file文件到云端,并返回链接

    有的文件、图片等信息可以上传到云端上,然后使用链接调用,这样会更加的方便和快捷。

    <form id="form">
        <input type="file" id="input">
        <input type="text" id="text">
    </form>
    <button id="button">上传</button>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">
        $("#button").click(function () {
            if (window.FormData){
                var FormData = new FormData();
                FormData.append("file",document.getElementById("input").files[0]);
                var XMLHttpRequest = new XMLHttpRequest();
                XMLHttpRequest.open("POST","此处为上传的接口");
                XMLHttpRequest.onload = function () {
                    if (XMLHttpRequest.status === 200){
                        var response = JSON.parse(XMLHttpRequest.response);
                        $("#text").val(response.data);
                    } else {
                        alert("Failure");
                    }
                };
                XMLHttpRequest.send(FormData);
            }
            else {
                alert("莫名错误");
            }
        });
    </script>
  • 相关阅读:
    AutoLayout动画
    实现毛玻璃效果
    合并静态库
    GCDAsyncSocket~
    iOS下URL编码
    OC多线程之GCD ----- 2
    堆和栈的区别
    Effective Objective-C 2.0重读笔记---2
    Android手机端抓包方法
    Android APK反编译
  • 原文地址:https://www.cnblogs.com/gwcyulong/p/6677138.html
Copyright © 2011-2022 走看看