获得响应仍然无法更新阵列

时间:2015-12-10 14:45:30

标签: jquery arrays ajax

HTML(dynamically added table):    
<td>
    <input type = "textbox" name = "Adj_qty[]" size = "3%" class = "form-control Adj_qty" id ="up_Adj_qty"
</td>
<td>
    <input type = "checkbox" value = "" name = "ms_confrim_qty[]"class ="ms_confrim_qty" id = "ms_confrim_qty">
</td>
<td style = "display:none">
    <input type = "textbox" value = '+b.id+' name = "indent_autoid[] " class = "indent_autoid" id = "up_indent_autoid">
</td>
 <button  type="button" type="submit" class="btn btn-info">Submit</button>

控制器:

public function approval_qty()
{
    $appr_qty = array();
    $indentserial_id = $this->input->post('indent_autoid');
    $appr_qty['approval_qty'] = $this->input->post('Adj_qty');
    $this->outpatient_model->update_row('tra_indent_item_dt',array('id'=>$this->input->post('indent_autoid')),$appr_qty);

    $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode(array("response" => 'updated')));
    }

JS:

var up_qty = {
        ajax: 1,
        up_array :[],
        up_array['id'] : $('#up_indent_autoid').val(),
        up_array['Adj_qty'] : $('#up_Adj_qty').val(), }

var base_url = "<?php echo base_url();?>";
$.ajax({
    url:  base_url+"/indent_approval/approval_qty",
    type: 'POST',
    data: stringify(up_qty),
    dataType: 'json',
    success: function(data) {
        alert("Updated Successfully");
        location.reload(); 
    },
    error: function() {
        alert('Error.');
    }
});

尝试更新阵列。 如何在type = submit / button时传递数组。 获得响应仍然无法更新阵列帮助我更新。

当我尝试执行此获取数组时,当我为没有数组执行相同操作时,我可以发布仍然无法更新的数据

现在收到错误信息如: 遗失:在财产ID之后

1 个答案:

答案 0 :(得分:0)

您的点击按钮事件应该如下所示,假设您的动态代码包含在tr标记

 $('input[type="submit"]').on('click',function(e){
        e.preventDefault();
        var up_qty = {
                        ajax: 1,
                        indent_autoid : $(this).parent('tr').find('#up_indent_autoid').val(),
                        Adj_qty : $(this).parent('tr').find('#up_Adj_qty').val(),

                        }
    var base_url = "<?php echo base_url();?>";
    $.ajax({
        url:  base_url+"/indent_approval/approval_qty",
        type: 'POST',
        data: up_qty,
        dataType: 'json',
        success: function(data) {
            alert("Updated Successfully");
            location.reload(); 
        },
        error: function() {
            alert('Error.');
        }
    });
    });