By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

Confirm with Ajax

P: 75
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:
Expand|Select|Wrap|Line Numbers
  1. function confirmPost() {
  2.   var agree = confirm("Are you sure you want to remove?");
  3.   if ( agree ) {
  4.     return true;
  5.   } else {
  6.     return false;
  7.   }
  8. }
  9.  
I then use the function in this event:
Expand|Select|Wrap|Line Numbers
  1.         $('#POCs').delegate( "a.remove", "click", function(){
  2.           confirmPost();
  3.           var id = $(this).attr( 'id' ).replace( /remove-/, '' );
  4.           var team_id = $('#auto_cat').val();
  5.           $.ajax({
  6.             type: "POST",
  7.             url: "delete.php",
  8.             data: { id: id, bucket_id: team_id },
  9.             success: function(resp){
  10.               $('#POCs').empty();
  11.               $('#POCs').html( resp );
  12.             }
  13.           });
  14.           return false;
  15.         });
  16.  
The dialog box comes up, but if I click 'OK' or 'Cancel' nothing happens.

Any assistance on this matter would be greatly appreciated!
Jul 19 '11 #1

✓ answered by Dormilich

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
Expand|Select|Wrap|Line Numbers
  1. if (!confirmPost()) {
  2.     return false;
  3. }

Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
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
Expand|Select|Wrap|Line Numbers
  1. if (!confirmPost()) {
  2.     return false;
  3. }
Jul 19 '11 #2

P: 75
I just needed to add a little bit of logic to get it going. Thanks for your help!
Jul 19 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.