1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Laravel 9 Ajax Update Record Returning 404 error

Discussão em 'Outras Linguagens' iniciado por T.A., Janeiro 10, 2025 às 19:33.

  1. T.A.

    T.A. Guest

    I am trying to update a database record with ajax. The code below is returning a 404 error code.

    Javascript

    data = {
    id: item_id,
    our_cost: new_price,
    _token: "{{csrf_token()}}",
    };

    $.ajax({
    url: '/change_item_price/{id}/{our_cost}',
    data: data,
    type: 'POST',
    success: function( data ) {
    console.log(data);
    }
    });


    Route

    Route::post('/change_item_price/{id}/{our_cost}',[itemController::class, 'change_item_price'])->name('change_item_price');



    Controller

    public function change_item_price($id, $our_cost){
    $get_id = Item::findOrFail($id);
    DB::table('items')
    ->where('id', $get_id)
    ->update([
    'our_cost' => $our_cost
    ]);
    return Item::where('id',$id)->first();
    }

    Continue reading...

Compartilhe esta Página