本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Pushing other parameters in serializeArray in AJAX Not Working

发布于2023-03-19 07:15     阅读(1192)     评论(0)     点赞(27)     收藏(2)


I've been trying to fix my AJAX code to push extra data but I always get this error: POST http://localhost/forexcargo_dev/partners/invoice/update net::ERR_EMPTY_RESPONSE.

Here's my code full AJAX code:

    // new addons
    var edit_new_addons = [];
    var edit_new_addon_amnts = $('#form_create_invoice table.order-tbl tbody tr.edit_new_charges_per_box');
    $.each(edit_new_addon_amnts,function(){
        var $tr = $(this).closest('tr'); //edit_new_charges_per_box
        var addon_cat = $(this).find('select.edit_add_other_addons option:selected').text();
        var addon_cat_id = $(this).find('select.edit_add_other_addons option:selected').val();
        var addon_amnt = $(this).find('input.edit-add-addon-amount').val();
        
        if (addon_cat.length > 0 ){
            edit_new_addons.push({'category':addon_cat, 'category_id': addon_cat_id, 'amount':addon_amnt, 'order_id':$tr.data('order_id')});
        }  
    });
    
    //existing addons
    var edit_existing_addons = [];
    var edit_existing_addon_amnts = $('#form_create_invoice table.order-tbl tbody.edit_items tr.edit_charges_per_box');
    $.each(edit_existing_addon_amnts,function(){
        var addon_cat = $(this).find('select.edit_other_addons option:selected').text();
        var addon_cat_id = $(this).find('select.edit_other_addons option:selected').data('id');
        var addon_amnt = $(this).find('input.edit-addon-amount').val();
        
        if (addon_cat.length > 0 ){
            edit_existing_addons.push( {'category':addon_cat, 'category_id': addon_cat_id, 'amount':addon_amnt, 'order_id':$(this).data('order_id')} );
            
        }  
    });
    info_ajaxAnim_show(true,'Loading...');
    var edit_invoice_data = $('#form_create_invoice').serializeArray();
    edit_invoice_data.push({name: 'invoice_date', value: $('input#edit-inv_date').val()});
    edit_invoice_data.push({name: 'addons', value: edit_new_addons});
    edit_invoice_data.push({name: 'delete_addons', value: remove_addon_id});
    edit_invoice_data.push({name: 'existing_addons', value: edit_existing_addons});
    $.ajax({
        type: "POST", 
        "url": window.base_url+'partners/invoice/update', 
        data: $.param(edit_invoice_data),//{'addons':edit_new_addons, 'delete_addons':remove_addon_id, 'existing_addons':edit_existing_addons},
        dataType : 'JSON',
        contentType: "application/json; charset=utf-8",
        success: function (response) {
            console.log(response);
            info_ajaxAnim_show(false);
            var alert_type = '';
            if(response.success == true){
                alert_type = 'info';
            } else {
                alert_type = 'warning';
            }
            $('#show_invoice_modal').modal('hide');
            $('div.alert_invoice_holder').html('<div class="alert alert-' + alert_type + ' alert-dismissible text-left" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' + response.message + response.email_msg + '</div>');
            tblinvbu.ajax.reload();
        },
        error: function (MLHttpRequest, textStatus, errorThrown) {
            console.log("There was an error: " + errorThrown);  
            alert(errorThrown);
        }
    });
});

Here's the part that's giving the error:

    edit_invoice_data.push({name: 'addons', value: edit_new_addons});
    edit_invoice_data.push({name: 'delete_addons', value: remove_addon_id});
    edit_invoice_data.push({name: 'existing_addons', value: edit_existing_addons});

UPDATE: I narrowed down my code and did some test again. The error occurs when I change the amounts under the existing_addons. But when I re-select the dropdown beside it, it's working.

I already tried checking edit_invoice_data in console.log() but I don't see any issues with it. I also tried creating a separate AJAX request for them but the result is still the same. What could I be doing wrong?


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/515927/97822f92b08275e063e0/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

27 0
收藏该文
已收藏

评论内容:(最多支持255个字符)