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 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面