admin管理员组

文章数量:1297038

In my admin panel I'm editing user details with Jquery/Ajax by clicking on a link. It's successfully working but I want to show confirmation dialog/popup box before request is send to server. If It's yes then my function (myfunc1) will be executive otherwise it will be close. My current code is look like this.

<td width="70"><a href="#" onClick="myfunc1('<?php echo $uid;?>') "><input type="button" value="Edit Details" class="button" /></a></td>

function myfunc1(id) {
    id = id;
    $.ajax({
        url: 'edit_user_details.php',
        type: 'post',
        data: {
            'id': id
        },
        success: function (response) {
            //$('#edit_user_result').html(response);          
            $('#sent_password_result' + id).html(response);
            setTimeout(function () {
                $('input[type=submit]').attr('disabled', false);
                window.location.href = "users.php";
            }, 5000);
        }
    });
}

How can I do this with jquery/Javascript ? Thank you for your help.

In my admin panel I'm editing user details with Jquery/Ajax by clicking on a link. It's successfully working but I want to show confirmation dialog/popup box before request is send to server. If It's yes then my function (myfunc1) will be executive otherwise it will be close. My current code is look like this.

<td width="70"><a href="#" onClick="myfunc1('<?php echo $uid;?>') "><input type="button" value="Edit Details" class="button" /></a></td>

function myfunc1(id) {
    id = id;
    $.ajax({
        url: 'edit_user_details.php',
        type: 'post',
        data: {
            'id': id
        },
        success: function (response) {
            //$('#edit_user_result').html(response);          
            $('#sent_password_result' + id).html(response);
            setTimeout(function () {
                $('input[type=submit]').attr('disabled', false);
                window.location.href = "users.php";
            }, 5000);
        }
    });
}

How can I do this with jquery/Javascript ? Thank you for your help.

Share Improve this question edited May 3, 2014 at 5:37 Greg 2,1731 gold badge22 silver badges23 bronze badges asked May 3, 2014 at 5:33 BabuBabu 4552 gold badges14 silver badges33 bronze badges 3
  • 2 What is id = id for? – Barmar Commented May 3, 2014 at 5:34
  • @Barmar It's a user id. In my php code it's looping within while() – Babu Commented May 3, 2014 at 5:36
  • I mean why are you setting a variable to itself. That doesn't do anything. – Barmar Commented May 3, 2014 at 5:37
Add a ment  | 

1 Answer 1

Reset to default 7

You can call confirm()

function myfunc1(id) {
    if (confirm("OK to submit?")) {
        $.ajax({        
            url: 'edit_user_details.php',
            type: 'post',             
            data: {'id' : id},
            success: function(response) {
            //$('#edit_user_result').html(response);          
                $('#sent_password_result'+id).html(response);
                setTimeout(function() {
                    $('input[type=submit]').attr('disabled', false); 
                    window.location.href = "users.php"; 
                }, 5000 );  
            }           
        });
    }
}

Or you can call it in the onclick:

onclick="if (confirm('OK to submit?')) { myfunc1('<?php echo $uid;?>'); } "

本文标签: javascriptHow do i implement a confirmation dialogbox before ajax request is send to serverStack Overflow