<div class="row" id="getsum">
<?php $i=0;$j=0;
$sum=Session::get('sumofac');
// dd($sum);
echo 'sum= '.$sum;
foreach(@$vehicles as $vehicle_details) {$i++; if($vehicle_details->is_airport_trips == 1 && $vehicle_details->is_private_airport==1 ) {
echo ' inside private ';
?>
<div class=" col-sm-12 col-md-12 col-lg-3 @if($vehicle_details->is_shared_airport) shared_airport_yes @endif
@if($vehicle_details->is_private_airport) <?php $j++;?> private_airport_yes @endif">
<div class="shared_airport_box vehicles shared_vehicles text-center @if($vehicle_details->is_shared_airport) shared_airport_yes @endif @if($vehicle_details->is_private_airport) <?php $j++;?> private_airport_yes @endif" style="min-height: 400px;">
<div class="options__container--option <?= ($i==1 || $j==1 && $vehicle_details->is_private_airport==1)?'checked11':'';?> " >
<input id="chb1_{{$vehicle_details->id}}" type="radio" value="{{$vehicle_details->id}}" name="vehicle_id" data-value="{{$vehicle_details->minimum_hr}} !! {{$vehicle_details->psngr_price_1}} !! {{$vehicle_details->vehicle_name}}" class="shared_airport_box_label <?= ($i==1 || $vehicle_details->is_private_airport==1)?'autochecked':'';?>" >
<label for="chb1_{{$vehicle_details->id}}" class="shared_airport_box_label">
<img src="{{ url('core/public/public/Image/'.$vehicle_details->image) }}">
<h4 class="options__container--title"> {{@$vehicle_details->vehicle_name}}</h4><p> {{ @$vehicle_details->description}}</p>
<p><span style="font-weight: bold;" id="shared_price_{{$vehicle_details->id}}"> </span></p>
</label>
</div>
</div>
</div>
<?php }
} ?> </div> <!-- getsumdivends -->
这是我的 div,其中 a 存储了来自控制器的会话,当我刷新页面时,我只想要 $sum=Session::get('sumofac');不更改整个 div,然后在 if 情况下使用 $sum
例如: if($vehicle_details->maxpassengers >= $sum ) 然后显示下面 div 的其余部分。
提前致谢!
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
public function updateSum(Request $request)
{
// Update the session value if needed
// Session::put('sumofac', $newValue);
$sum = Session::get('sumofac');
return response()->json(['sum' => $sum]);
}
$(document).ready(function () {
// Function to update the $sum value without refreshing the div
function updateSum() {
$.ajax({
url: "{{ route('updateSum') }}",
type: "GET",
dataType: "json",
success: function (data) {
// Update the $sum value in your HTML
var sum = data.sum;
$("#sumValue").text("sum= " + sum);
if (/* your condition based on $sum */) {
$("#restOfDiv").show();
} else {
$("#restOfDiv").hide();
}
},
error: function (xhr, status, error) {
console.error(error);
},
});
}
// Call the updateSum function initially
updateSum();
// You can also call updateSum whenever you need to refresh the $sum value.
// For example, after some user interactions.
// Example:
$("#someButton").click(function () {
updateSum();
});
});