How do I check if file exists in jQuery or pure JavaScript?

前端 未结 18 2076
闹比i
闹比i 2020-11-22 00:56

How do I check if a file on my server exists in jQuery or pure JavaScript?

18条回答
  •  抹茶落季
    2020-11-22 01:39

    I was getting a cross domain permissions issue when trying to run the answer to this question so I went with:

    function UrlExists(url) {
    $('').load(function() {
        return true;
    }).bind('error', function() {
        return false;
    });
    }
    

    It seems to work great, hope this helps someone!

提交回复
热议问题