jeudi 29 juin 2017

laravel ajax pass multiple variables to controller?

I need to pass 4 variables to controller so that I can do what I want to do with it, however I get an error:

Missing argument 1 for App\Http\Controllers\ProfileController::getGoogle()

Here's my Controller:

function getGoogle($lat, $lng, $destinationLat, $destinationLng) {
    print_r($lat);
    print_r($lng);
    print_r($destinationLat);
    print_r($destinationLng);
}

and ajax:

function getDirections(lat, lng, destinationLat, destinationLng) {
      $.ajax({
          url: '/google/',
          type: 'post',
          data: { lat: lat, lng: lng, destinationLat: destinationLat, destinationLng: destinationLng },
          dataType: 'json',
          success: function() { alert('hello!'); },
          error: function() { alert('boo!'); },
          headers: {
              'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
          }  
        });

Route:

Route::post('google/', 'ProfileController@getGoogle');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire