Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在ajax post上找不到路由_Php_Laravel - Fatal编程技术网

Php 在ajax post上找不到路由

Php 在ajax post上找不到路由,php,laravel,Php,Laravel,我正在尝试使用ajax创建一个依赖的select,下面是我的JS $("#make").change(function(){ $.ajax({ url: "{{ url('chauffeur/ajax_vehicle_model') }}?make=" + $(this).val(), method: 'GET', success: function(data) { $('#model').html(data.htm

我正在尝试使用ajax创建一个依赖的select,下面是我的JS

$("#make").change(function(){
    $.ajax({
        url: "{{ url('chauffeur/ajax_vehicle_model') }}?make=" + $(this).val(),
        method: 'GET',
        success: function(data) {
            $('#model').html(data.html);
        }
    });
});
我的路线是这样的

Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
    Route::get('chauffeur/ajax_vehicle_model','Admin\ChauffeurController@get_vehicle_model');
});
我的控制器里有这个

public function get_vehicle_model(Request $request)
{
    ....
}

但是我有一个404错误,你知道我做错了什么吗?

试着像这样改变你的路线

Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
    Route::get('chauffeur/ajax_vehicle_model','Admin\ChauffeurController@get_vehicle_model');
});
路由文件

Route::get('chauffeur/ajax_vehicle_model', ['as'=> 'chauffeur.ajax.vehicle',  'uses' => 'Admin\ChauffeurController@get_vehicle_model']);
现在您的js代码应该是这样的(如果您的js代码位于
.blade.php
文件中)


试试这个。

如您所见,您的路由组
前缀中有一个参数,值为
admin

这将在该路由组中的路由前面加上
admin
。这样,JS中的url应该如下所示:

url(“admin/chauffeur/ajax_vehicle_model”)

你把javascript代码放在哪里了?在.js文件或刀片文件中?@yasaryousuf在
@section('javascript')
@endsection
之间的刀片文件中,必须将js中的更改路线设置为
路线('admin.chauffer.ajax.vehicle')