简体   繁体   中英

Delete Confirmation in Client Side

In my Ajax function there's a table & inside it there's a Delete button.It's working But i wanted to do When someone Click that delete button then it needs to ask the Confirmation dialogue.I know it's easily we can do it with OnClientClick="return confirm('Do you want to delete?') but here already OnClick,How can i do this ?

My Ajax Function

 html += '<td>' + '<input type="button" value="Delete" onclick="deleteUploadFile(this,' + value.Id + ')">' + '</td>';

DeleteUploadedFile Function

function deleteUploadFile(element, id) {

         debugger;
         var url = '<%= ResolveUrl("/WebMethods.aspx/RemoveUploadedFile") %>'; 

         $.ajax({
             url: url,
             type: "POST",
             data: JSON.stringify({ id: id }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (Result) {
                 /*on success*/
                 $(element).parents('tr:first').remove();
             },
             error: function (e, x) {
                 //alert(x.ResponseText);
             }
         });
         }

Write your confirm inside your function:

function deleteUploadFile(element, id) {

     debugger;
     var url = '<%= ResolveUrl("/WebMethods.aspx/RemoveUploadedFile") %>'; 

     if(confirm('Deleting file. Are you sure?')) {
         $.ajax({
             url: url,
             type: "POST",
             data: JSON.stringify({ id: id }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (Result) {
                 /*on success*/
                 $(element).parents('tr:first').remove();
             },
             error: function (e, x) {
                 //alert(x.ResponseText);
             }
         });
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM