javascript - Get event after function complete -


i have form people can delete records;

<a href="/delete/1" class="confirm-action">delete record 1</a> <a href="/delete/2" class="confirm-action">delete record 2</a> <a href="/delete/3" class="confirm-action">delete record 3</a> 

to ensure sure, using "are sure" confirmation script (popconfirm) gives nice little popup confirmation.

$(".confirm-action").popconfirm(); 

if user clicks cancel, nothing happens. if click 'yes' - link processed , record deleted. working intended.

now instead of following link (when user clicks 'yes'), want fire ajax request:

$('.confirm-action').click(function(event) {      event.preventdefault();      $.ajax({             // ajax stuff here       }); }); $(".confirm-action").popconfirm(); 

the problem when try this, functions fired in correct order when expected, except event null, script fails.

how "preventdefault()" when event null, and/or manually event prevent link being followed browser?

edit: jsfiddle showing problem.

as noted in comments, plugin horrible , plays _data(events) ie plays internal event management of jquery.

if aren't concerned ui, suggest go normal confirm() used in so.

i've created while typing answer:

$.fn.nativeconfirm = function (options) {     return this.click(function () {         var bool = confirm(options.text);         bool ? options.yes.call(this) : options.no.call(this);     }); } 

example:

$('a').nativeconfirm({     yes: function(){       alert('yes');     },     no:function(){       alert('no');     },     text: 'seriously?' }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -