Confirm with Ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BaseballGraphs
    New Member
    • Sep 2010
    • 75

    #1

    Confirm with Ajax

    Hello,

    I am trying to confirm whether a user wants to perform a desired action using AJAX and am having trouble getting it to work.

    I have this function:
    Code:
    function confirmPost() {
      var agree = confirm("Are you sure you want to remove?");
      if ( agree ) {
        return true;
      } else {
        return false;
      }
    }
    I then use the function in this event:
    Code:
            $('#POCs').delegate( "a.remove", "click", function(){
              confirmPost();
              var id = $(this).attr( 'id' ).replace( /remove-/, '' );
              var team_id = $('#auto_cat').val();
              $.ajax({
                type: "POST",
                url: "delete.php",
                data: { id: id, bucket_id: team_id },
                success: function(resp){
                  $('#POCs').empty();
                  $('#POCs').html( resp );
                }
              });
              return false;
            });
    The dialog box comes up, but if I click 'OK' or 'Cancel' nothing happens.

    Any assistance on this matter would be greatly appreciated!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    The dialog box comes up, but if I click 'OK' or 'Cancel' nothing happens.
    why should something happen? the code does what it is told to do.

    maybe you should add a breaking condition
    Code:
    if (!confirmPost()) {
        return false;
    }

    Comment

    • BaseballGraphs
      New Member
      • Sep 2010
      • 75

      #3
      I just needed to add a little bit of logic to get it going. Thanks for your help!

      Comment

      Working...