我无法使用laravel从AJAX恢复的两个表中的数据表中显示数据

时间:2020-03-15 12:16:00

标签: ajax laravel

enter image description here我能够以两个dataP和ps表的形式检索我的数据,我想将其显示在我的数据表中,但它为我提供了undefined的所有字段。

SalarieController.php

 public function etatq1u(request $request){
        $pointages = Pointage::get();
        $dataP = DB::table('Salaries AS s')
         ->leftJoin('pointages AS p', 'p.salarie_id', '=', 's.id')
         ->leftJoin('avances AS a', 'a.salarie_id', '=', 's.id')
         ->groupBy('s.id')
         ->selectRaw('s.id AS "matricule",
                      s.nom AS "nom",
                      SUM(p.sold) as montant,
                      SUM(a.montantA) as avance')
         ->get();
              return response(compact('dataP','pointages'));
          }

AJAX

 $.ajax({
          type: 'get',
          url: "{{ route('salarie.etatq1u') }}",
          data: {
                 'annee':ann,
                 'mois':moi,
                 'salarie_id':sal,
                 'chantier_id':chan,
                 'unite' : unite
                },
          success: function(data1){
              console.log(data1);
              $.each(data1, function(i,val) {
                let html = `<tr>
                          <td>${data1[i].matricule}</td>
                          <td>${data1[i].nom}</td>
                          <td>${data1[i].avance}</td>
                        </tr>`;
             $('#mytable').append(html);
            });
          },
          error: function(){
              console.log('error');
          },
          });

0 个答案:

没有答案