I have an AJAX script to insert data from a form to MySQL database. This is the AJAX.
<!-- SUBMIT FORM VIA AJAX -->
$("#f_product").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "<?php echo site_url('con_product/ins_product'); ?>",
data: data
}).success(function() {
alert("Products list is ready to be printed");
window.open("<?php echo site_url('con_product/print_product'); ?>","_blank");
window.open("<?php echo site_url('con_product/form_product'); ?>","_self");
});
});
<!-- END SUBMIT FORM VIA AJAX -->
The AJAX script successfully insert data from the form to database. But somehow, the script on success is not working. Why?
The behavior of this AJAX are:
- Insert data to database - success
- Show alert
- Open new page for print purpose.
- Refresh current page to a new form.