路线票/BDkkh9ef不支持POST方法。支持的方法:GET、HEAD

问题描述 投票:0回答:1

我想使用

.on('submit', function (event)
提交表单,但我收到此错误,但不知道原因。该错误显示所有这些门票路线,而不仅仅是我发布的示例。

这是路线部分:

Route::post('tickets/update', [SupportTicketController::class, 'update'])->name('tickets.update');
Route::resource('tickets', SupportTicketController::class)->except(['destroy', 'create', 'update']);
Route::post('tickets/{ticket}/assigned', [EmployeeAssignedController::class, 'employeeTicketAssigned'])->name('tickets.assigned');
Route::get('tickets/{id}/delete', [SupportTicketController::class, 'destroy'])->name('tickets.destroy');
Route::get('tickets/download/{id}', [SupportTicketController::class, 'download'])->name('tickets.downloadTicket');
Route::post('tickets/delete/selected', [SupportTicketController::class, 'delete_by_selection'])->name('mass_delete_tickets');
Route::post('tickets/{ticket}/comments', [SupportTicketCommentController::class, 'index'])->name('ticket_comments.index');
Route::post('tickets/store_comments/{ticket}', [SupportTicketCommentController::class, 'store'])->name('ticket_comments.store');
Route::get('tickets/{id}/delete_comments', [SupportTicketCommentController::class, 'destroy'])->name('ticket_comments.destroy');
Route::post('tickets/{ticket}/details', [SupportTicketController::class, 'detailsStore'])->name('ticket_details.store');
Route::post('tickets/{ticket}/notes', [SupportTicketController::class, 'notesStore'])->name('ticket_notes.store');

查看 JavaScript 示例:

$('#assigned_form').on('submit', function (event) {
event.preventDefault();

$.ajax({
    url: "{{ route('tickets.assigned',$ticket) }}",
    method: "post",
    data: new FormData(this),
    contentType: false,
    cache: false,
    processData: false,
    dataType: "json",
    success: function (data) {
        let html = '';
        if (data.errors) {
            html = '<div class="alert alert-danger">';
            for (let count = 0; count < data.errors.length; count++) {
                html += '<p>' + data.errors[count] + '</p>';
            }
            html += '</div>';
        }
        if (data.success) {
            html = '<div class="alert alert-success">' + data.success + '</div>';
        }
        $('#assigned_result').html(html).slideDown(300).delay(500).slideUp(300);
    }
})

});

这是正在调用的路线:

public function employeeTicketAssigned(Request $request, SupportTicket $ticket)
{
$role = Role::find(Auth::user()->role_id);
if($role->hasPermissionTo('assign-ticket'))
{
    $employees = $request->input('employee_id');
    $ticket->assignedEmployees()->sync($employees);
    $notificable = User::where('role_id', 1)
        ->orWhere('id', $ticket->employee->id)
        ->orWhere('id', $ticket->customer->id)
        ->orwhereIntegerInRaw('id', $employees)
        ->get();
    Notification::send($notificable, new TicketAssignedNotification($ticket));

    return response()->json(['success' => __('تم إدخال البيانات بنجاح')]);
}

return response()->json(['success' => __('غير مصرح لك')]);
}
ajax laravel routes
1个回答
0
投票

看来您没有传递路线的第二个参数。

例如

Route::get('/post/{post}/comment/{comment}', function () {
    //
})->name('comment.show');

route('comment.show', ['post' => 1, 'comment' => 3]);

就您而言,可能是

url: "{{ route('tickets.assigned', ['ticket' => $ticket]) }}",
© www.soinside.com 2019 - 2024. All rights reserved.