我有一个通过jQuery绑定到一个链接的ajax调用,我希望它被一个确认对话框拦截.但是,无论选择哪个选项(即使用户只是关闭对话框),ajax调用都会触发.
@H_403_13@解决方法
有没有办法让确认在同步上下文中工作?
HTML:
<a href="#" class="removeItem delete">remove</a>
jQuery的:
$('.delete').click(function () { confirm('Are you sure you want to delete this?'); }); $('.removeItem').click(function (event) { event.preventDefault(); $.ajax({ url: 'myUrl',type: "POST",data: { // data stuff here },success: function () { // does some stuff here... } }); });
$('.removeItem').click(function (event) { if (confirm('Are you sure you want to delete this?')) { $.ajax({ url: 'myUrl',data: { // data stuff here },success: function () { // does some stuff here... } }); } });