#13112 closed bug (notabug)
.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 exampleaction: ok
, orjavascript: 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.
Change History (4)
comment:1 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
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. :(
comment:3 Changed 10 years ago by
'A' tags are special in the way network events work. Resolution is to cancel the default event action with event.preventDefault();
comment:4 Changed 10 years ago by
Yeah. But the question is: I need do that, or jQuery need handle that natively?
This is not a jQuery bug. Please talk out your frustrations on a forum or blog post.