2017-06-21 35 views
1

更新:现在,当我改变poule_id我得到一个空白表,里面什么都没有,当我直接去了网址,如:选择的onChange表刀片观点

https://mydomaine.eu/go/public/competition/search/equipes?poule_id=2

我得到:
表“ \ n \ n \ n \ n \ n“

我试着做一个功能,改变我的刀片表的结果,用一个选择框显示配方(队),但是现在我什么都不知道在那里我犯了一个错误,它可能是在JavaScript代码

希望有人能够帮助解决这个问题,非常感谢提前

我试图改变我的表将取决于poule_id一个选择框是这样的:

<select id="poule"> 
    @foreach($select_poules as $select_poule) 
     <option value="{{$select_poule->id}}">{{$select_poule->lb_poule}}</option> 
    @endforeach 
</select> 

我的表包含谁依赖于团队一个poule_id:

@foreach($equipes as $equipe) 
    <tr> 
    <td> 
     <a href="{!! route('club.show', $equipe->equipe->structure->id) !!}">{{$equipe->equipe->structure->nom_structure}}</a> 
    </td> 
    <td> 
     <a href="{!! route('equipe.show', $equipe->equipe->id) !!}">{{$equipe->equipe->lb_equipe}}</a> 
    </td> 
    <td> 
     {!! Form::text('nb_bonus') !!} 
    </td> 
    </tr> 
@endforeach 

这里我的控制器:

public function searchEquipes(Request $request) 
{ 

    if ($request->has('poule_id')) { 

     $equipes = EquipePoule::where('poule_id' , $request->poule_id)->get(); 

     $competition = Compet::where('id' , 1)->first(); 

     $categorie_compet = CategorieCompet::pluck('lb_categorie_compet' , 'id'); 

     $categorie_age = CatgEquipe::pluck('lb_catg_equipe' , 'id'); 

     $structure_rattachement = Structure::select('num_structure', 'nom_structure' , 'id') 
      ->where('type_structure_id' , '1') 
      ->orWhere('type_structure_id' , '2') 
      ->orWhere('type_structure_id' , '3') 
      ->get() 
      ->mapWithKeys(function($i) { 
       return [$i->id => $i->num_structure.' - '.$i->nom_structure]; 
      }); 
     $poules = Poule::where(['compet_id' => $competition->id])->get(); 

     $rencontres = Rencontre::where(['compet_id' => $competition->id])->orderBy('dt_rencontre' , 'DESC')->get(); 

     $designations = RencontreOfficiel::where(['compet_id' => $competition->id])->get(); 

     $classements = Classement::where(['compet_id' => $competition->id])->orderBy('nb_point_classement' , 'DESC')->get(); 

     $equipe_to_select = Equipe::select('lb_equipe', 'structure_id' , 'catg_equipe_id' ,'id') 
      ->get() 
      ->mapWithKeys(function($i) { 
       return [$i->id => $i->lb_equipe.' - '.$i->structure->nom_structure.' - ' .$i->catg_equipe->lb_catg_equipe]; 
      }); 

     $stade = Stade::select('lb_nom', 'ville_stade' , 'cd_post_stade' , 'id') 
      ->get() 
      ->mapWithKeys(function($i) { 
       return [$i->id => $i->lb_nom.' - '.$i->ville_stade.' - '.$i->cd_post_stade]; 
      }); 



     $find_equipes = $competition->equipes; 

     $domicile = $find_equipes->mapWithKeys(function ($i) { 
      return [$i->id => $i->lb_equipe.' - '.$i->structure->nom_structure.' - ' .$i->catg_equipe->lb_catg_equipe]; 
     }); 


     //ON AFFICHE QUE LES EQUIPES ENREGSITRER DANS LE COMPETITION 
     $find_equipes = $competition->equipes; 
     $visiteur = $find_equipes->mapWithKeys(function ($i) { 
      return [$i->id => $i->lb_equipe.' - '.$i->structure->nom_structure.' - ' .$i->catg_equipe->lb_catg_equipe]; 
     }); 

     $select_poules = Poule::where('compet_id' , 1)->get(); 

     $journees = Journee::where('compet_id' , 1)->get(); 

     $journee_to_select = Journee::where('compet_id' , 1)->pluck('nm_journee' , 'id'); 


     return response()->json([ 

      'table' => view("competitions/show", compact('equipes' , 'competition' , 'categorie_age' , 'categorie_compet' , 'classements' , 'equipe_to_select' , 'structure_rattachement' , 'poules' , 'select_poules' , 'journee_to_select' , 'journees' , 'rencontres', 'designations' , 'stade', 'domicile' , 'visiteur'))->render(), 

     ]); 

    }else { 

     echo 'on trouve rien '; 
    } 

这里我的javascript:

<script> 
    $('#poule').change(function() { 
     $.ajax({ 
      type: 'GET', 
      dataType: "json", 
      url : 'search/equipes/', 
      data : { 
       poule_id : document.getElementById('poule').value 
      }, 
      success:function(data){ 
       $('#equipes').html(data.table); 
      }, 
     }); 
    }); 
</script> 
+0

好吧,所以你想要在div容器中使用ajax注入整个视图?在JavaScript控制台或PHP端有没有错误? – Asur

+0

是的确切!问题是我得到任何错误的JavaScript或PHP –

+0

我已经更新了我的答案,请尝试以下步骤,并告诉我错误在哪里,以便我可以为您提供更好的答案。 – Asur

回答

1

没有得到错误的反馈是相当怪异,但我会改变你的AJAX功能HTML期待具体的数据类型开始,因为不需要转换为JSON和在javascript中将其重新转换为html。因此,它应该是这样的:

你的控制器:

public function searchEquipes(Request $request) 
{ 
    if ($request->has('poule_id')) { 
     $equipes = $equipes = EquipePoule::wherePouleId($request->poule_id)->get(); 
     return view("competitions/show", compact('equipes'))->render(); 
    } 
} 

你的Ajax:

<script> 
    $('#poule').change(function() { 
     $.ajax({ 
      type: 'GET', 
      dataType: "html", 
      url : 'search/equipes/', 
      data : { 
       poule_id : document.getElementById('poule').value 
      }, 
      success:function(data){ 
       $('#equipes').html(data); 
      } 
     }); 
    }); 
</script> 

然后,我会遵循一些步骤来检查在失败是:

  • 事件是否到达ajax?
  • ajax是否到达服务器?
  • 服务器是否将呼叫路由到控制器?
  • 控制器是否正确返回视图?
  • ajax是否更新dom容器?

告诉我失败的地步,我会编辑更多信息。

+0

好吧,我有一些更新!我编辑帖子,希望你能看到问题在哪里 –