Jquery Ajax调用未按预期工作
我试图在成功呼叫Realex(处理信用卡交易的公司)后清除一些会话变量。会话变量包含我的购物车内容,因此,一旦交易成功,我希望将其清除。我的代码如下:Jquery Ajax调用未按预期工作,jquery,ajax,Jquery,Ajax,我试图在成功呼叫Realex(处理信用卡交易的公司)后清除一些会话变量。会话变量包含我的购物车内容,因此,一旦交易成功,我希望将其清除。我的代码如下: jQuery.ajax({ async: false, url: templateuri+'/realex_go_pay.php',
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 the shopping cart.
jQuery.ajax({
async: false,
url: templateuri+'/realex_empty_cart.php'
});
self.location = thankyoupage+'?order='+orderid+'&key='+orderkey;
}else{
alert(data);
}
}
});
第一次调用realex_go_pay.php没有问题。但是对realex_empty_cart.php的第二次调用似乎不起作用。在realex_empty_cart.php中,我只有两行代码:
unset($_SESSION['cart']);
unset($_SESSION['coupons']);
我认为Archer在他的评论中有一个很好的解决方案,但原因可能与缓存有关。默认情况下,jQuery.ajax将允许浏览器缓存GET请求的响应。这意味着它将不会与服务器通信。加
cache: false
更改代码中的选项以强制其转到服务器
success: function(data){
// Hide payment indicator.
jQuery('.realex_payindicator').hide();
data = data.split("|");
if (data[0] == '00'){
// Empty the shopping cart.
jQuery.ajax({
async: false,
cache: false,
url: templateuri+'/realex_empty_cart.php'
});
self.location = thankyoupage+'?order='+orderid+'&key='+orderkey;
}else{
alert(data);
}
}
(有关更多信息,请参阅)
欧文你有没有和firebug或者类似的东西联系过?是否已发出ajax请求?realex_empty_cart.php是否成功响应?请确保您在响应php文件中的“success”消息使第二个ajax调用也成为post并添加
数据:{}
与arunes一致,确保您的第二个ajax请求正在运行。在第一次成功后执行console.log(data),以确保第二条if语句(data[0]='00')
为真。在realex\u empty\u cart.php中打印($\u会话)。回报是多少?你在那个页面上有会话吗?