I have a URL which I want to open in a FancyBox (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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…