24

jQueryを介してリンクにバインドされたajax呼び出しがあり、確認ダイアログでインターセプトしたい。ただし、ajax呼び出しは、選択されているオプションに関係なく起動します(ユーザーがダイアログを閉じただけの場合でも)。

同期コンテキストで機能するように確認を機能させる方法はありますか?

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...
        }
    });
});
4

1 に答える 1

101
$('.removeItem').click(function (event) {
    if (confirm('Are you sure you want to delete this?')) {
        $.ajax({
            url: 'myUrl',
            type: "POST",
            data: {
                // data stuff here
            },
            success: function () {
                // does some stuff here...
            }
        });
    }
});
于 2011-06-17T10:11:12.210 に答える