Php laravel,ajax未在生产模式下工作此服务器上未找到请求的URL/appointment/45/edit

Php laravel,ajax未在生产模式下工作此服务器上未找到请求的URL/appointment/45/edit,php,ajax,laravel,Php,Ajax,Laravel,我尝试使用ajax和laravel更新数据,但在生产中,它给了我一个错误(在该服务器上找不到请求的URL/appointment/45/edit) 我使用的是ajax,laravel5.7 $(document).on('click', '.edit', function() { id = $(this).attr('id'); $.ajax({ url: "/appointment/" + id + "/edit",

我尝试使用ajax和laravel更新数据,但在生产中,它给了我一个错误(在该服务器上找不到请求的URL/appointment/45/edit)

我使用的是ajax,laravel5.7

    $(document).on('click', '.edit', function() {
        id = $(this).attr('id');
        $.ajax({
             url: "/appointment/" + id + "/edit",
            dataType: "json",
            success: function(html) {
                $('#name').val(html.data.name);
                $('#appdate').val(html.data.appdate);
                $('.modal-title').text("Edit Appointment");
                $('#action_button').val("Edit");
                $('#action').val("Edit");
                $('#modal-default').modal('show');
            }
        })
    });



route
Route::resource('appointment','AppointmentController');



controller
    public function edit($id)
    {
        if(request()->ajax())
        {
            $data = Appointment::findOrFail($id);
            return response()->json(['data' => $data]);
        }
    }
在此服务器上找不到请求的URL/appointment/45/edit


我尝试使用ajax更新数据,并使其在本地工作,但在生产中,它给了我一个错误(在此服务器上找不到请求的URL/appointment/45/edit)

在ajax调用中使用命名路由

url:“{route('route.name')}}”

并添加ajax调用类型

类型:'post'或类型:'get'


在ajax调用中,使用命名路由,如

url:“{route('route.name')}}”

并添加ajax调用类型

类型:'post'或类型:'get'

在js中:

路由文件中(web.php)

在控制器中:

    public function edit($id)
    {     
         $data = Appointment::findOrFail($id);
         return response()->json(['data' => $data]);
    }
在js中:

路由文件中(web.php)

在控制器中:

    public function edit($id)
    {     
         $data = Appointment::findOrFail($id);
         return response()->json(['data' => $data]);
    }

您的路线应该类似于
route::resource('/appointment/{id}/edit','AppointmentController@edit');谢谢bassxzero,但仍然是相同的错误您的路线应该类似于
路线::资源('/appointment/{id}/edit','AppointmentController@edit');谢谢bassxzero,但仍然是相同的错误如何添加此路由器的参数,url:{{route('appointment.edit')}}+id,就像您在控制器中添加路由一样:url:{{route('appointment.edit','id')}。。。这里id是在发送ajax请求之前必须创建的javascript变量。如果您发送get请求,而不仅仅是使用ajax请求的'data'属性添加,如:--data:{id:id}注意如何使用此路由器添加参数,url:“{route('appointment.edit')}}”+id,就像您在控制器中使用route添加一样:url:{{route:}('appointment.edit','id')}…这里id是在发送ajax请求之前必须创建的javascript变量。如果要发送get请求,则只需添加ajax请求的'data'属性,如:--data:{id:id}注意这一点
    public function edit($id)
    {     
         $data = Appointment::findOrFail($id);
         return response()->json(['data' => $data]);
    }