XMLHttpRequest to read an external file

后端 未结 2 1896
心在旅途
心在旅途 2021-01-20 15:48

I want to retrieve the data contained in a text file (from a given URL) through JavaScript (running on the client\'s browser).

So far, I\'ve tried the following appr

2条回答
  •  梦谈多话
    2021-01-20 16:16

    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})
    

提交回复
热议问题