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

前端 未结 18 2104
闹比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

    It works for me, use iframe to ignore browsers show GET error message

     var imgFrame = $('');
     if ($(imgFrame).find('img').attr('width') > 0) {
         // do something
     } else {
         // do something
     }
    

提交回复
热议问题