发布于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">×</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黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!