I use jQuery to bind to all links on the page (I use the 'click' event, but tried various combinations of "mousedown" and "mouseup" along with bind () and live () to no avail).
I can intercept a click without problems (with all of the above methods). What I'm trying to do is send some data using a GET request, and when it finishes, enable the default click click action.
Since I am exchanging a cross-domain, I have to use GET, not POST, and therefore cannot make a synchronous call.
Therefore, I need to return "false" from the intercepted click event, save the event for later, and then manually start it again after the connection is completed. If I return true, the link will be disconnected in the middle when the page location changes.
The problem is that I cannot find a way to fire the local click event later.
var storedEvent; $("#wrapper a").bind('click', function(event, processed) { $(event.target).unbind('click'); // temporary to make code branching easier storedEvent = event.target; event.stopPropagation(); $.ajax({ dataType: 'jsonp', data: linkData, jsonp: 'cb', url: 'xxx', cache: false, complete: function(response) { // How do I now go back and fire the native click event here? $(storedEvent).click(); } }); return false; }
I tried using click () and trigger () where indicated, but didn't work.
I know that the presentation succeeds and the code forks correctly - I debugged this far. I just can't play the event.
Please note that I cannot do something simple, for example, save href and set window.location later - some of the links have their own onClicks, and others with the specified varius parameters. I would like to simply reproduce the event that I stopped earlier.
I started using event delegation with live () and had everything there was except this - I simplified it to bind () to simplify the problem.