2017-06-21 49 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

好吧,我有一些更新!我編輯帖子,希望你能看到問題在哪裏 –