Aronaman
2 months ago

assign variable in ajax

Posted 2 months ago by Aronaman

controller pass variable to blade and how can pass to ajax variable?

controller

 public function create(Request $request, Room $room)
    {
        $resultCount=2;
	$diffDate= $check_out->diffInDays($check_in);
        return view('International', compact('room','diffDate',' resultCount'));
    }

blade

 <label > Select Qty:</label><br>

<div  class="form-check">
     <select  id="qty" name="qty">
	<option value="">--- Select Qty ---</option>
		@for ($i = 1; $i < $resultCount; $i++) 
		<option value="{{$i}}">{{$i}}</option>
		@endfor
      </select>
   </div>

<h4 class="d-flex justify-content-between align-items-center mb-3">
        <span class="text-muted">Reservation Info</span>
</h4>

 <li class="list-group-item d-flex justify-content-between lh-condensed">
	 <div>
	       <h6 class="my-0">No Date</h6>      
	 </div>
	       <span class="text-muted">{{ $diffDate }}</span>
 </li>

<li class="list-group-item d-flex justify-content-between lh-condensed">
	 <div>
	         <h6 class="my-0">Quantity</h6>   
	  </div>
<!-- {{ $room->quantity }} -->
	  <span id="roomQty" class="text-muted"></span>
</li>

//ajax

$('#qty').change(function(){
	  var price=room->price;// i dont know how to assign ($price Value) 
          var noDate=diffDate; // i dont know how to assign ($diffDate  value)
	   var qty = $("#qty").val();
$.ajax(
            {
                url: "{{route('ajax.international.qtyChange')}}?qty="+qty,
                type: 'GET',
                success: function (res){
                    if(res){
                        $("#roomQty").html(res.qty);
                    }else{
                       $("#roomQty").empty();
                    }
    }
   });// ajax 
});

any help please

Please sign in or create an account to participate in this conversation.