dimanche 9 février 2020

Ajax laravel dropdown not returning the id of selected value

I am passing the hotel id as a parameter to my function to get all the rooms in that hotel. But it is returning an error. I want to return in a JSON format the id of the hotel. this is my javascript function

function showRooms($hotel_plan_id) {
   var id = $hotel_plan_id; 
 if (id !== "") {
var token = $('meta[name="_token"]').attr('content');
     $.ajax({
    url: '/rooms'+id,
    type: "Get",
    dataType: 'JSON',
    data: "{id:" + JSON.stringify(id) + ", _token:" + token + "}",
success:function(data)
    {
      alert('xdata:' + data);
    //$('#'+dependent).html(result);
    },
    error: function (result) {
      alert("Error occur in the rooms()");
    }
 });

this is my controller

public function rooms(id $id){
    dd($id);
    $response = array(); 
    $response =$id;

    return response()->json($response);
}

this is my route

Route::get('/rooms', 'HomeController@rooms')->name('/rooms');


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UxQCYq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire