javascript - 带 javascript 参数的 Laravel 路由

标签 javascript laravel-5 routes

我有一个函数,当用户单击时,它从表中返回一个参数。数据是通过 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/

相关文章:

laravel - 如何检查laravel中是否使用了分页

Linux : how to set default route from C?

javascript - 使用 jquery 进行下拉列表验证

javascript - 创建输入表单以添加/删除关键字

javascript - 当 Javascript Validation 返回 false 时如何防止服务器端操作?

php - 迁移 Laravel 5 中的单个文件

javascript - 咕噜声 : get line numbers for errors

php - Laravel 表单验证独特,使用 2 个字段

angular - 子路线最初未以 Angular 加载

amazon-web-services - 将 www 子域重定向到 Route 53 上的顶级(裸)域(不使用 S3)?