Skip to main content

Bug Tracker

Side navigation

#13112 closed bug (notabug)

Opened December 23, 2012 08:13PM UTC

Closed December 23, 2012 09:08PM UTC

Last modified January 05, 2013 01:57AM UTC

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

Reported by: david71rj Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:
Description

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.

Take a look: http://jsfiddle.net/ZwYYT/

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().

Take a look: http://jsfiddle.net/VexYh/1/

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 example action: ok, or javascript: void(0);, return false by default.

Take a look: http://jsfiddle.net/wAB4T/1/

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.

Attachments (0)
Change History (4)

Changed December 23, 2012 09:08PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

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

Changed December 24, 2012 01:18AM UTC by david71rj comment:2

jQuery trigger a XHR .error() empty, without a tip about the motive of fail, like a unexpected abort... It's not a bug?

Well... I'll try forum. :(

Changed January 05, 2013 01:49AM UTC by anonymous comment:3

'A' tags are special in the way network events work. Resolution is to cancel the default event action with event.preventDefault();

Changed January 05, 2013 01:57AM UTC by david71rj comment:4

Yeah. But the question is: I need do that, or jQuery need handle that natively?