Harsha M V
Harsha M V

Reputation: 54949

jQuery Dialog Box

I have a delete button where on clicking the button i want a dialog box to pop up and then on clicking ok it should do the Ajax call else shouldnt do anything. here is Code

$('.comment-delete').click(function () {
    var deleteID = $(this).attr('id');

    $.ajax({
        url: "account/deleteComment/" + deleteID,

        success: function () {
            $("#comment-"+deleteID).slideUp("fast");
        }

    });

    return false;
});

Upvotes: 1

Views: 324

Answers (3)

Alex Rashkov
Alex Rashkov

Reputation: 10015

if (confirm("Your question")) { 
    $.ajax({
        url: "account/deleteComment/" + deleteID,
        success: function () {
            $("#comment-"+deleteID).slideUp("fast");
        }
    });
} 

Upvotes: 2

Jake
Jake

Reputation: 4899

You can do the dialog confirm with just a single extra line of code.

$('.comment-delete').click(function () {

    // Confirm Dialog.
    if (!confirm('Do you really want to delete?')) return false;

    var deleteID = $(this).attr('id');

    $.ajax({
        url: "account/deleteComment/" + deleteID,

        success: function () {
            $("#comment-"+deleteID).slideUp("fast");
        }

    });

    return false;
});

Upvotes: 1

Aaron Hathaway
Aaron Hathaway

Reputation: 4315

Are you asking a question? I assume it's not working for you. I don't think you're passing the variables correctly. Take a look at jQuery.get(), that may be suitable for what you're trying to do.

Upvotes: 1

Related Questions