Skip to content Skip to sidebar Skip to footer

Why Is Code In Ajax Success Call Is Not Working?

I have an AJAX script to insert data from a form to MySQL database. This is the AJAX. $('#f_product').on('submit',function(event){ event.pr

Solution 1:

The success is the name of the callback function and not the promise.

You should use:

$.ajax({
    type: "POST",
    url: "<?phpecho site_url('con_product/ins_product'); ?>",
    data: data,
    success: function() {
        alert("Products list is ready to be printed");
        window.open("<?phpecho site_url('con_product/print_product'); ?>","_blank");
        window.open("<?phpecho site_url('con_product/form_product'); ?>","_self");
    }
});

Or the done promise:

$.ajax({
    type: "POST",
    url: "<?phpecho site_url('con_product/ins_product'); ?>",
    data: data
}).done(function() {
    alert("Products list is ready to be printed");
    window.open("<?phpecho site_url('con_product/print_product'); ?>","_blank");
    window.open("<?phpecho site_url('con_product/form_product'); ?>","_self");
});

Solution 2:

I'm not sure if there is .success function. But you can try this:

$.ajax({
    type: "POST",
    url: "<?phpecho site_url('con_product/ins_product'); ?>",
    data: data,
    success: function(){
        alert("Products list is ready to be printed");
        window.open("<?phpecho site_url('con_product/print_product'); ?>","_blank");
        window.open("<?phpecho site_url('con_product/form_product'); ?>","_self");
    }
});

Solution 3:

According to http://api.jquery.com/jquery.ajax/

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

What if your replace success with done?

Otherwise, success should be a property of the object you throw into $.ajax({...}) with the anonymous function as its value.

Post a Comment for "Why Is Code In Ajax Success Call Is Not Working?"