玩转图片上传————原生js XMLHttpRequest 结合FormData对象实现的图片上传

var form=document.getElementById("formId");
        var formData=new FormData(form);
        var oReq = new XMLHttpRequest();
        oReq.onreadystatechange=function(){
          if(oReq.readyState==4){
            if(oReq.status==200){
                var json=JSON.parse(oReq.responseText);
                console.log(json);
            }
          }
        }
        oReq.open("POST", "http://localhost:3000/doup");
        oReq.send(formData); 

  该方法是可以跨域的(端口不同的跨域),亲测可用!

  服务端如何处理的解决方案看我的这篇文章http://www.cnblogs.com/theone67/p/6698762.html

原文地址:https://www.cnblogs.com/theone67/p/6905180.html