.ajax() fail when you click in a[href]

.ajax() fail when you click in a[href]

I posted it into bugs page, but dmethvin told that I need post here before. So, here I'm.

Original post:

Well... If you have a a[href^="abc:"] element then you click on it the browser will start a new request, but this pattern will do not execute anything, so you will stand on the same page.

If you start an .ajax() request and .click() in this element, you will have an error, because your Ajax request will be aborted by browser.

The problem is that jQuery not show clearly what happen.

Easy solution: You can solve this problem by return false in .click().

So I suggest two solution:

    • Easy but will not solve anything: return a error.message content like "Your request be aborted" (or just simulate a .abort());
    • Harder but efficient (need be reviewed): if your a[href] match with /\w\w+\:/ (like my exampleaction: ok, or javascript: void(0);, return false by default.

Note: in Chrome it'll try to load, but Chrome will cancel request, if you check the Network DevTools you can see it in red.

I tried on 1.8.2, 1.8.3 and edge.

dmethvin's reply:

This is not a jQuery bug. Please talk out your frustrations on a forum or blog post.