php - How to post data using ajax/jquery after confirmation popup -


i send id hidden input type in form, when confirmation message pops , user clicks ok. right cant make code without confirmation popup work, no errors, refresh , nothing happens. may thinking why need confirm adding item cart that's because need delete item database later on.

<script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript">  $(document).ready(function(){ $('#add').click(function(){ var id = $("#get_id").val()  $.confirm({         'title'     : 'delete confirmation',         'message'   : 'you delete user.continue?',         'buttons'   : {             'yes'   : {                  'action': function(){$a.ajax({ url: 'http://localhost/com/index.php/shopping_basket/view_basket', type: 'post', data: { id: id },     success: (function(){     alert('added' + id);  });                 }               },             'no'    : {                  'action': function(){}  // nothing in case. can omit action property.             }         }     });  }); }); </script> 

the form

<form id="basket" method="post" action=""> <input type="hidden" id="get_id" value="<?php echo $id ?>"> <input type="submit" id="add" value="add"> </form> 

btw what's difference in using window.location.href send instead of this?

<?php $id ?> won't contain without echo - , ruler pointed out, forgot name anyway:

<input type="hidden" name="whatsmyname" value="<?php echo $id ?>"> 

further, need add submit handler form, not click handler, , cancel normal behavior:

$('#basket').on('submit',function(e){     e.preventdefault(); // prevents form submitting     $a.ajax({         url: 'http://localhost/com/index.php/cart/add_cart',         type: 'post',         data: { id: id }, // comma missing         success: (function(){             alert('added' + id);         });     }); }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -