doupinyan0186
2018-08-16 20:24
浏览 74
已采纳

Laravel AJAX PUT不接收数据

I am using Laravel 5.6.33 and when wanting to send the information with the method PUT it is impossible for me, the update function does not receive anything.

this is my javascript:

$("#SaveArea").on("click",function(e){

            event.preventDefault();



            var token = $("#token").val();

            $.ajax({

                url: "/areas/{{ $area->AreaID }}",
                headers:{'X-CSRF-TOKEN':token},

                contentType: false,
                processData: false,
                data: {"name":"alex"},
                type: 'put',

                beforeSend: function () {
                    // alert("akus")
                },
                success: function (response) {

                    console.log(response)
                    // swal(response['mensaje'],'', "success");

                }
            });

  });

form data:

<form class="form-group" method="POST" action="/areas/{{ $area->AreaID }}" autocomplete="off" id="FormArea">
    @method('PUT')

    @csrf

update function:

public function update(Request $request, Area $area)
{

    return $request->all() ;

web.php

// Areas
Route::resource('/areas','AreasController');
Route::post('/areas/store','AreasController@store');
Route::get('/areas','AreasController@getAreas');
Route::get('/area/new',function(){
return view("rrh.new_area");});
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwuge6201 2018-08-16 20:48
    已采纳

    type can only be GET or POST

    Remove contentType: false, processData: false

    Change: event to e

    点赞 评论

相关推荐 更多相似问题