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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -