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
Post a Comment