javascript - Function not taking variable correctly -
here code:
var makesessions = 1; function destroysession() { jquery.noconflict(); if(destroysessions == 1 || destroysessions == 2) { destroysessions = 0; jquery('.opc-ajax-loader').show(); jquery.ajax({ url: '../../unsetpercentpayment.php', type: 'post', data: { shippingmethod: '1' }, datatype: 'json', success: function (data) { jquery('.opc-ajax-loader').hide(); jquery('#shippingprice').show(); jquery.each(data.grandtotal, function(index, grandtotal) { if(makesessions == 1) { jquery('#newprice').text(grandtotal + ' лвs.'); } if(makesessions == 2) { mytotal = grandtotal / 2; jquery('#newprice').text(mytotal + ' лвa.'); } }); } }); makesessions = 2; } }
on first time when function destroysession()
runs must have makesessions
1
, in order run:
if(makesessions == 1) { jquery('#newprice').text(grandtotal + ' лвs.'); }
however appears every first time when run destroysessions
runs part of code:
if(makesessions == 2) { mytotal = grandtotal / 2; jquery('#newprice').text(mytotal + ' лвa.'); }
and problem not understand.. why when makesessions 1 runs code makesessions = 2 ?
can me out resolve problem?
change this
} }); makesessions = 2;
to
makesessions = 2; } });
Comments
Post a Comment