S
S
Sergey Chazov2019-04-13 13:01:15
Laravel
Sergey Chazov, 2019-04-13 13:01:15

How to get information using ajax requests in laravel?

It is necessary to load information from the database into the modal window using ajax.
I built a structure, but it does not work.
JQ:

function editTask(id){
 
          $.ajax({
                    url : "/taskContent/",
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    data: {
                    "id": id
                    },
                    type: "POST",
                    }).done(function( result )
                                             {
    $('#mainModalBody').html( result );
          });

router
Route::POST('/taskContent/','[email protected]');

Controller
public function taskContent($id){
    echo $id;	
  /*return response()->json(array('foo' => 'bar'));*/
}

Inserted a meta tag into the view
<meta name="csrf-token" content="{{ csrf_token() }}">

As a result, I expect to receive the value of the ID variable in the modal window.
Instead, I have an error: GET bi/taskContent 405 (Method Not Allowed)
tell me how to correctly collect information using ajax from the controller.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ARX2, 2019-04-14
@chazovs

Can you make it simpler and clearer:

function editTask(id){
         $.post('/taskContent/', {id : id}, function(result ){
          $('#mainModalBody').html( result );
         });
          });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question