I have a dropdown with values such as:
<select style="padding-top:300px;">
<form id="tram_stops">
<option onchange="tram_stops(this.value);" value="abraham-moss-tram">Abraham Moss tram stop</option>
<option onchange="tram_stops(this.value);" value="altrincham-tram">Altrincham tram stop</option>
<option onchange="tram_stops(this.value);" value="anchorage-tram">Anchorage tram stop</option>
and on change call ajax:
function tram_stops(tram_value) {
$.ajax({
url: '/tramsearch' + tram_value,
type: 'post',
dataType: 'html',
success: function(data) {
},
error: function(data) {
},
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
}
And controller:
public function tram_search($tram_value) {
$tram_text = $tram_value;
if ($tram_text) {
$client = new Client();
$crawler = $client->request('GET', 'https://beta.tfgm.com/public-transport/tram/stops/'.$tram_text);
echo "<div class=table-responsive><table class='table table-striped table-bordered table-hover'>";
$tfgm = $crawler->filter('table[id="departures-data"]')->each(function ($node) {
echo $node->html()."\n";
});
}
}
So what I want to achieve:
allow user to choose a tram stop. Value is a slug which is used in request('GET') in Controller. I then want to display data from that request and output it on the page.
As of this moment, when I choose an option from a dropdown, nothing happens.