I tried almost all solutions but they all come back on a success level as if it exists when it does not. Can someone help?
I try it on files that DONT exist but it comes back as if it exists which makes no sense.. I even output the playlisturl and comes back exactly how i want it but my guess is, its not search right?
What i tried: //My Vars
var playlistname = "index";
var playlisturl = "/var/lib/mpd/playlists/"+ playlistname + ".m3u";
Tried:
function doesFileExist(urlToFile)
{
    var xhr = new XMLHttpRequest();
    xhr.open('HEAD', urlToFile, false);
    xhr.send();
    if (xhr.status == "404") {
        console.log("File doesn't exist");
        alert('does not exist');
        return false;
    } else {
        console.log("File exists");
        alert('exists: ' + playlisturl);
        return true;
    }
}
doesFileExist(playlisturl);
And:
$.UrlExists = function(url) {
    var http = new XMLHttpRequest();
    http.open('HEAD', url, false);
    http.send();
    return http.status!=404;
}
if($.UrlExists(playlisturl)){
    alert('exists: ' + playlisturl);
}else{
    alert('does not exist');
}
And:
$.ajax({
    url: playlisturl,
    type:'HEAD',
    error: function()
    {
        alert('does not exist');
    },
    success: function()
    {
        alert('exists: ' + playlisturl);
    }
});
