How to test a URL in jQuery

I have a URL which I want to open in a [FancyBox][1] (or any other overlay-type pop-up). I don't know in advance whether URL is good, so I want to test it. If invalid - I won't attach the fancyBox plugin to that particular URL, it will just be a regular link. **How can I test a URL before attaching a plugin to it?** Tried doing something like: $("a.overlay").each(function() { var xhr = $.get(this.href, function(data, status) { // never executed in case of a failed request }); if (xhr.status && xhr.status === 404)) { // not good, do nothing } else { // can attach plugin here } }); The problem is, `xhr` will not always be defined because JS doesn't wait for the request to complete. Similarly, I cannot use the callback function, because it doesn't seem to be executing in case the request fails (I can see it in Firebug, but that's not very useful). Thanks and have a good weekend everyone. [1]:

以上就是How to test a URL in jQuery的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准