jquery - Ajax call not working as expected -
i'm trying clear session variables after successful call realex ( company processes credit card transaction ). session variables contain shopping cart contents, once transaction successful, want clear out. code follows:
jquery.ajax({ async: false, url: templateuri+'/realex_go_pay.php', type: 'post', data: { amount: ordertotal, orderid: orderid, orderkey: orderkey, cardtype: type, cardnumber: number, cardname: name, expdate: expiry, cvv: cvv, issueno: issueno }, success: function(data){ // hide payment indicator. jquery('.realex_payindicator').hide(); data = data.split("|"); if (data[0] == '00'){ // empty shopping cart. jquery.ajax({ async: false, url: templateuri+'/realex_empty_cart.php' }); self.location = thankyoupage+'?order='+orderid+'&key='+orderkey; }else{ alert(data); } } });
the first call realex_go_pay.php working no problem. second call realex_empty_cart.php not seem working. in realex_empty_cart.php, have 2 lines of code:
unset($_session['cart']); unset($_session['coupons']);
i think archer has solution in comment, reason caching. default, jquery.ajax allow browser cache response requests. means not communicate server. add
cache: false
to options in code force go server.
success: function(data){ // hide payment indicator. jquery('.realex_payindicator').hide(); data = data.split("|"); if (data[0] == '00'){ // empty shopping cart. jquery.ajax({ async: false, cache: false, url: templateuri+'/realex_empty_cart.php' }); self.location = thankyoupage+'?order='+orderid+'&key='+orderkey; }else{ alert(data); } }
(see http://api.jquery.com/jquery.ajax/ more info)
owen
Comments
Post a Comment