简体   繁体   中英

Javascript - Check if (URL)-file exists over HTTPS

I already tried getting the file with this Code, the problem is, the code works with http requests but not with https request (which is what i need)

 function isThere(url) { var req = new XMLHttpRequest(); // XMLHttpRequest object try { req.open("HEAD", url, false); req.send(null); return req.status == 200 ? true : false; } catch (er) { return false; } } function setUser() { var user = document.getElementById("userName").value; if (isThere("https://dev.sentinex.de/ulogv2/" + user) == true) { alert("File exists!"); } else { alert("File doesn't exist!"); } }

Does anyone know how i can change the code to work with HTTPS Requests or how i could rewrite it so that i could get HTTPS Requests?

PS: I am just requesting from my own domain - so no other domains for requests are needed.

Please posts the domain of the resource that executes the code. If you are on Http. You must use a bypassSecurityTrust

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM