【发布时间】:2019-03-18 11:04:23
【问题描述】:
我目前正在使用 ajax 数据请求处理前端表单。 In my code i have this in the php block that gets displayed in a partial when a category in select-box is selected to show subcategories.
function onChangeCat()
{
$this['subs'] = Cat::whereHas('parent', function ($query) use($cats){
$query->where('cats','=', $cats );
})->pluck('cat_title', 'id');
我正在尝试将其连接到一条路线,以便当用户单击一个类别时,相关的子类别会显示在第二个选择框中。
这是我的路由文件,参数为#id of category select-box
Route::get('ajax/{cats}' , function () {
//
return json_encode();
});
我如何连接 php 块中的代码和路由来工作,以便只显示相关的类别子类别?
【问题讨论】:
-
data request不能与routes结合,按照设计data request将请求 当前 url 并从当前页面、布局、部分搜索ajax-handlers[代码块] ( onXyz() ) 和in included components,所以你不能在外部为数据请求 API 指定 URL[route],如果你想使用路由,那么你需要手动做 Ajax。 -
有没有办法在没有路由的情况下将 id 传递给 onXyz()?
-
添加了
pass value到ajax handler,的答案请查看
标签: php ajax laravel octobercms