Dec 17, 2017
0
Level 1
Storing to session problem
What should I do when the session doesn't save the input I give most of the time (and by most of the time, I mean it accepts and stores the variable, sometimes it doesn't.
function to get the value input by the user
$("#submit-bttn").click(function () {
var customPayment = $('#custom-payment').val();
customPayment = parseFloat(customPayment);
var test = $('#GrandTotalPrice').text();
test = test.replace(/,/g,'');
test = parseFloat(test);
saveLoanCustomPaymentState(customPayment);
selectedPlan(+((customPayment/test).toFixed(2)));
/* console.log("test" + customLoanDownPayment);
console.log("test" + downpaymentPlan);*/
});
ajax function to send data to session
function saveLoanCustomPaymentState(customPayment) {
customLoanDownPayment = customPayment;
//console.log("saveLoanCustomPaymentState" + customLoanDownPayment);
$.ajax({
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
method: "post",
data: {
customPayment: customLoanDownPayment
},
url: '{{ url('queue/edit/save-loan-custom-payment-state')}}',
dataType: 'json',
success : function(customPayment) {
customLoanDownPayment = customPayment;
}, {{-- end success function --}}
{{-- error function is common to all ajax calls --}}
@include('layouts.include.ajax-error.script')
}); {{-- end ajax --}}
} {{-- end function --}}
controller
public function saveLoanCustomPaymentState() {
//variable declarations
$customPayment = Input::get('customPayment');
session(['queue.loan.custom-payment' => $customPayment]);
// $customPayment = Session::get('queue.loan.customPayment');
return Response::json($customPayment);
}
declaration in the controller
$selectedCustomPayment = Session::get('queue.loan.custom-payment');
blade line that calls from the session
customLoanDownPayment = '{{ isset($selectedCustomPayment) ? $selectedCustomPayment : null }}';
sometimes it stores the value, sometimes it doesn't. what causes such behavior?
Please or to participate in this conversation.