duanlijia5864 2018-06-28 04:56
浏览 50
已采纳

当我尝试更新codeigniter中的内容时,id将被取消定义,仅使用id 1

$('#showdata').on('click', '.item-edit', function(){

            var id = $(this).attr('data');
            $('#update_model').modal('show');
         //s  $('#myform').attr('action', '<?php echo site_url() ?>/Admin/Authorisation/update');
      $.ajax({
             type: 'ajax',
             method: 'get',
             url: '<?php echo site_url() ?>/Admin/Authorisation/edit',
             data: {id: client_id},
             async: false,
            // dataType: 'json',
             success: function(data)
             {

                 alert(id);
                 $('input[name=fname]').val(data.client_fname);
                 $('input[name=lname]').val(data.client_lname);
                 $('input[name=email]').val(data.client_email);
                 $('input[name=phone]').val(data.client_phone);
                 $('input[name=country]').val(data.client_country_id);
                 $('input[name=client_id]').val(data.id);

             }, 

             error: function()
                {
                    alert('could not Edit');
                }

         });    
        });  
            function get_data(){
            $.ajax({
                type: 'ajax',
                url: '<?php echo site_url() ?>/Admin/Authorisation/get_data',
                async: false,
                dataType: 'json',
                success: function(data){
                    var html = '';
                    var i;
                    for(i=0; i<data.length; i++){
                        html +='<tr>'+
                                    '<td>'+data[i].client_id+'</td>'+
                                    '<td>'+data[i].client_fname+'</td>'+
                                    '<td>'+data[i].client_lname+'</td>'+
                                    '<td>'+data[i].client_email+'</td>'+
                                    '<td>'+data[i].client_phone+'</td>'+
                                     '<td>'+data[i].client_country_id+'</td>'+
                                     '<td>' +data[i].password+'</td>'+
                                     '<td>'+data[i].status+'</td>'+
                                    '<td>'+
                                        '<a href="javascript:;" class="btn btn-info item-edit" data="'+data[i].client_id+'">update</a>'+
                                        '<a href="javascript:;" class="btn btn-danger item-delete" data="'+data[i].client_id+'">Delete</a>'+
                                    '</td>'+
                                '</tr>';
                    }
                    $('#showdata').html(html);
                },
                error: function(){
                    alert('Could not get Data from Database');
                }
            });
        }
        });


    </script> 

id is going undefined when i try to update something in codeigniter its taking only id 1. Not gething the correct id. when i alert my id its saying undefined. and in place of id its going null so could not update any thing

  • 写回答

1条回答 默认 最新

  • dsxay48646 2018-06-28 05:58
    关注

    the problem is you are getting your id in variable named id, but you are passing it as client_id.

         data: {id: client_id},
    

    this should be data: {id: id},

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么