我有一个函数,当用户单击时,它从表中返回一个参数。数据是通过 ajax 提取的,这就是我使用 javascript 的原因。
我的功能很简单:
<script>
function selectItem(id)
{
alert(id);
}
</script>
我想要的是传递一个 URL,它将 id 传递给 lavavel 路由(而不是简单地检查传递的参数的警报),类似于
{{ URL('quotations/p_customerselected/{id}') }}
我确实尝试过
{{ URL('quotations/p_customerselected/') }} + id;
但是抛出了一个错误。
最佳答案
假设您的 Controller 名称为 QuotationController, Controller 函数名称为 viewcustomer。
在 web.php 中,为您的路线命名,例如
Route::post('/quotations/p_customerselected/{id}', 'QuotationController@viewcustomer')->name('quotations.p_customerselected');
现在在 JavaScript 中:
<script>
function selectItem(cust_id)
{
var url = '{{ route("quotations.p_customerselected", ":id") }}';
url = url.replace(':id', cust_id);
}
</script>
关于javascript - 带 javascript 参数的 Laravel 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44102058/