ajax - How to test a URL in jQuery -


I have a URL that I want to open in (or any other overlay-type pop-up). I do not already know that the URL is good, so I want to test it. If invalid - I will not attach the Fancybox plugin to that specific URL, it will be just a regular link How can I test a URL before attaching it to a plugin? Tried to do this:

  $ ("a.overlay"). Each (function () {var xhr = $ .get (this.href, function (data, position) {// was never executed in case of a failed request}}; if (excercity & amp; xhr. Status === 404)) {// no good, do not do anything} second {// can add plug-ins here}});  

The problem is, xhr will not always be defined because JS does not wait for completion requests. Similarly, I can not use the callback function, because if this request fails (I can see it in firebug, but this is not very useful) does not execute.

Thank you and good weekend everyone.

You can do this, however I can ask the question that this is the request for each link < / P>

  $ ("a.overlay"). Each (function () {var $ a = $ (this); $ .ajax ({type: 'gET', url: this.href, success: function () {// plugin plug here}, error: function ( } {// good no, log}});};  

If you are not going to do anything with the contents of the page, then you can only type 'head' with 'head' You can switch, only get the header of the requested page, which is fast and you know what you want.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -