Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在ajax codeigniter中使用foreach_Arrays_Ajax_Codeigniter - Fatal编程技术网

Arrays 如何在ajax codeigniter中使用foreach

Arrays 如何在ajax codeigniter中使用foreach,arrays,ajax,codeigniter,Arrays,Ajax,Codeigniter,亲爱的专家需要帮助如何在变量tbaris之间添加foreach: function show_infouser(Kode) { save_method = 'update'; $('#form')[0].reset(); // reset form on modals $('.form-group').removeClass('has-error'); // clear error class $('.help-block').empty(); /

亲爱的专家需要帮助如何在变量tbaris之间添加foreach:

function show_infouser(Kode)
   { save_method = 'update';
       $('#form')[0].reset(); // reset form on modals
       $('.form-group').removeClass('has-error'); // clear error class
       $('.help-block').empty(); // clear error string
       $.ajax({url : "<?php echo site_url('infouser/ajax_user')?>/" + Kode,
       type: "GET",
       dataType: "JSON",
       success: function(data){
         if (data == null)
         { showConfirmButton: false }); }
         else {
// want to show foreach in here
           var tbaris = '<tr><td style="width:3px; font-size:11px;"><center>'+data.No+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+data.Name+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+data.Job+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+data.Status+'</center></td>';
           $('#tableuser tbody').html(tbaris);
           $('#modal_form1').modal('show');
           $('.modal-title').text('SHOW ROOM');}},
          error: function (jqXHR, textStatus, errorThrown)
               {
                   alert('Error get data from ajax' + errorThrown);
                   alert('Error get data from ajax' + textStatus);
                   alert('Error get data from ajax' + jqXHR);
               }
           });
       }
功能显示\u信息用户(Kode)
{save_method='update';
$('#form')[0].reset();//在modals上重置表单
$('.form group').removeClass('has-error');//清除错误类
$('.help块').empty();//清除错误字符串
$.ajax({url:“/”+Kode,
键入:“获取”,
数据类型:“JSON”,
成功:功能(数据){
如果(数据==null)
{showConfirmButton:false});}
否则{
//想带foreach来这里吗
var tbaris=''+数据。无+'';
tbaris+=''+数据名+'';
tbaris+=''+数据.作业+'';
tbaris+=''+数据状态+'';
$('#tableuser tbody').html(tbaris);
$('modal#form1')。modal('show');
$('.modal title').text('SHOW ROOM');},
错误:函数(jqXHR、textStatus、errorshown)
{
警报('Error-get-data-from-ajax'+errorshown);
警报('Error get data from ajax'+textStatus);
警报('Error get data from ajax'+jqXHR);
}
});
}

使用
$尝试以下操作。each()

 function show_infouser(Kode)
       { 
           save_method = 'update';
           $('#form')[0].reset(); // reset form on modals
           $('.form-group').removeClass('has-error'); // clear error class
           $('.help-block').empty(); // clear error string

           $.ajax({
           url : "<?php echo base_url('infouser/ajax_user');?>/" + Kode,
           type: "GET",
           dataType: "JSON",
           success: function(response){
             if (response == null)
             { showConfirmButton: false } 
             else {
// want to show foreach in here
            var tbaris ='';
            $.each(response,function(index) {
            tbaris += '<tr><td style="width:3px; font-size:11px;"><center>'+response[index].No+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+response[index].Name+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+response[index].Job+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+response[index].Status+'</center></td>';
           }
           $('#tableuser tbody').html(tbaris);
           $('#modal_form1').modal('show');
           $('.modal-title').text('SHOW ROOM');
             }
         },
          error: function (jqXHR, textStatus, errorThrown)
               {
                   alert('Error get data from ajax' + errorThrown);
                   alert('Error get data from ajax' + textStatus);
                   alert('Error get data from ajax' + jqXHR);
               }
           });
       }
功能显示\u信息用户(Kode)
{ 
save_方法='update';
$('#form')[0].reset();//在modals上重置表单
$('.form group').removeClass('has-error');//清除错误类
$('.help块').empty();//清除错误字符串
$.ajax({
网址:“/”+Kode,
键入:“获取”,
数据类型:“JSON”,
成功:功能(响应){
如果(响应==null)
{showConfirmButton:false}
否则{
//想带foreach来这里吗
var-tbaris='';
$。每个(响应、功能(索引){
tbaris+=''+响应[索引]。无+'';
tbaris+=''+响应[索引]。名称+'';
tbaris+=''+响应[索引]。作业+'';
tbaris+=''+响应[索引]。状态+'';
}
$('#tableuser tbody').html(tbaris);
$('modal#form1')。modal('show');
$('.modal title').text('SHOW ROOM');
}
},
错误:函数(jqXHR、textStatus、errorshown)
{
警报('Error-get-data-from-ajax'+errorshown);
警报('Error get data from ajax'+textStatus);
警报('Error get data from ajax'+jqXHR);
}
});
}

同时发布您的控制器…code.您如何从服务器发送数据?Hikmat Sijapati,首先我在if(data==null)上出错,我将其更改为if(response==null),并在JSON数据的第1行第2列出现新的错误SyntaxError:JSON.parse:意外字符[了解更多信息]请发布控制器的代码,这也很容易。请在不使用
JSON.parse();
的情况下尝试一次。一些与括号相关的错误已被删除。在添加代码var data=JSON.parse(响应)之前,我的控制器没有问题;数据只显示第一行,因此我认为foreach中的问题是因为ajax不支持使用JSON.parse生成代码,但如果删除JSON.parse(),仍然会出错;数据只显示数据中的第一行数据,共有4行