lundi 2 mai 2016

Ajax request on click on laravel 5

I try to create a messages system I have create message drop down menu and when the user click on it all messages marked as read but the request doesn't sent to the server

I create:

Controller method:

public function viewed(Request $request)
{
    if ($request->isMethod('post')) {
        \App\Message::where('destination_id','=',Auth::user()->id)->update(['vu' => '1']);
        return 'done';
    }

}

route to this method:

Route::post('notification',['middleware' => 'auth','uses' =>'IndexController@viewed']);

on click event and ajax:

$('#dLabel').click(function(event) {
    event.preventDefault();
    console.log('geted');
    $.ajax({
      url: '/notification',
      type: 'POST',
      processData: false,
      contentType: false,
      success: function(data){
        console.log('done'+data);
      },
      async: true,
      error: function(data){
        console.log('No');
      }
    });
  });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire