【发布时间】:2023-10-14 12:19:02
【问题描述】:
我有一个下拉菜单,其中包含以下值:
<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>
并在更改调用 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')
}
});
}
和控制器:
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";
});
}
}
那么我想要达到的目标:
允许用户选择电车站。 Value 是一个 slug,在 Controller 的 request('GET') 中使用。然后我想显示来自该请求的数据并将其输出到页面上。
到目前为止,当我从下拉列表中选择一个选项时,什么都没有发生。
【问题讨论】:
-
你的选择和表单标签混淆了......我不建议在选择元素内打开表单:)
-
不会改变函数不运行的事实
-
好吧,祝你好运
标签: ajax laravel laravel-5 guzzle