更新:現在,當我改變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>
好吧,所以你想要在div容器中使用ajax注入整個視圖?在JavaScript控制檯或PHP端有沒有錯誤? – Asur
是的確切!問題是我得到任何錯誤的JavaScript或PHP –
我已經更新了我的答案,請嘗試以下步驟,並告訴我錯誤在哪裏,以便我可以爲您提供更好的答案。 – Asur