jQuery: Check if image exists

后端 未结 6 692
予麋鹿
予麋鹿 2020-11-27 17:20

I\'m loading an image path via jQuery $.ajax and before showing the image I\'d like to check if it in fact exists. Can I use the image load/ready event or something similar

6条回答
  •  感情败类
    2020-11-27 18:17

    Since you're already doing an AJAX request, I would offload this to the server-side app that is supporting your AJAX. It's trivial to check to see if a file exists from the server, and you could set variables in the data you send back to specify results.

提交回复
热议问题