XMLHttpRequest to read an external file

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 23:42:24

IT works using xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); in IE older versions. Chrome, Firefox and all sensible browsers use xhr

Frankly, if you want cross browser compatibility, use jquery

its pretty simple there:

var text="";
$.get(url, function(data){text=data;//Do something more with the data here. data variable contains the response})
var xhr = new XMLHttpRequest();
xhr.open('POST', '/uploadFile'); 
var form = new FormData();
form.append('file', fileInput.files[0]);
xhr.send(form);

It was previously impossible to upload binary data with XMLHttpRequest object, because it could not stand the use of FormData (which, anyway, did not exist at that time) object. However, since the arrival of the new object and the second version of XMLHttpRequest, this "feat" is now easily achievable

It's very simple, we just spent our File object to a FormData object and upload it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!