dimanche 28 juin 2015

Tried all jquery methods and js to check for file exist but all doesn't work

Tried all jquery methods and js to check for file exist but all doesn't work all give me that any file that exist or doesn't on my server / with my domain that it does exist although some dont... idk why it say that all does although they dont?!!! maybe something wrong with my server? idk :( i need help tried all of that

$.get('http://MyUrl/file.wav')
.done(function() { 
    alert('exists');

}).fail(function() { 
    alert('does not exist');

})

&

$.ajax({
  url: 'http://MyUrl/file.wav', //or your url
  type: 'GET',
  success: function(data){
    alert('exists');
  },
  error: function(data){
    alert('does not exist');
  },
})

&

    function doesFileExist(urlToFile)
    {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'http://MyUrl/file.wav', false);
        xhr.send();

        if (xhr.status == "404") {
            //return false;
    console.log('not exist');
        } else {
            //return true;
            console.log('file with that name exists exists');

        }}

&

$.ajax({
    url:'http://MyUrl/file.wav',
    type:'HEAD',
    error: function()
    {
        //file not exists

    },
    success: function()
    {
        //file exists
      console.log('file with that name exists exists');
    }
});

idk what else i do really but it frustrate me that it always give me exists or true no matter file exists or not.....

Aucun commentaire:

Enregistrer un commentaire