Answers for "js get file from url"

3

get filename from url js

var filename = location.pathname.substr(location.pathname.lastIndexOf("/")+1);
Posted by: Guest on October-29-2020
1

js get file content from url

// create a variable called content containing the content from https://URL/file
fetch("https://URL/file").then((r)=>{r.text().then((d)=>{let CONTENT = d})})
Posted by: Guest on October-30-2020
0

javascript read file from url

// read text from URL location
function getText(){
    var request = new XMLHttpRequest();
    request.open('GET', 'http://www.xxxxx.com/pocket.txt', true);
    request.send(null);
    request.onreadystatechange = function () {
        if (request.readyState === 4 && request.status === 200) {
            var type = request.getResponseHeader('Content-Type');
            if (type.indexOf("text") !== 1) {
                return request.responseText;
            }
        }
    }
}
Posted by: Guest on March-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language