Check it url / file exists - with Jquery

by jstenkvist

JavaScript

function checkIfRemoteFileExists(urlToCheck) {
$.ajax({
        url:'http://www.example.com/3.html',
        error: function()
        {
           alert('file does not exists');
        },
        success: function()
        {
            alert('file exists');
        }
    });
 

// Now to check if file exists call function
checkIfRemoteFileExists('http://www.yoursite.com/abc.html');

checkIfRemoteFileExists('http://www.google.de');