php - Ajax Form Submission & Javascript Confirm Error -


i have form submits through ajax, works @ moment. tried add confirm option allow / prevent ajax submission through adding following lines:

    var answer = confirm('submit now?');     return answer // answer boolean      if(answer) { ... } 

below full function, which, can see, fires on clicking submit button. error occurs when user selects okay in dialog. entire page refreshed , single ajax warnings returned @ top of blank screen. in normal case, without confirm code, error messages appear in div#result tag @ bottom of form.

$("#submitbtn").click(function() {          var answer = confirm('submit now?');         return answer // answer boolean          if(answer) {               $('#result').html('<img id="loading" src="images/loading.gif" />').fadein();             var input_data = $('#create_po').serialize();             $.ajax({                 type: "post",                 url:  "<?php echo "http://" . $_server['http_host'] . $_server['request_uri']; ?>",                 data: input_data,                 success: function(msg){                     $('#loading').remove();                     $('<div>').html(msg).appendto('div#result').hide().fadein('slow');                 }             });             return false;          }      }); 

how should implement confirm dialog doesn't refresh screen? suggestions appreciated. thanks!

you doing return answer. doesn't make sense here.

it stop javascript function, , return boolean. remove line, , you're set

also, add make submit not fireing if confirm box false ;)

if (answer){     // ajax call } else {     return false; } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -