ajax
error: function(jqXHR, textStatus, errorThrown) {
errorGo(textStatus, errorThrown);
},
errorGO()
function errorGO(status, error){
console.log('textStatus: %s, errorThrown: %s', status, error, location, type);
alert('Something went wrong :(');
$.ajax('https://xx.x.com/x/query.php', {
type: 'POST',
data: {
'message': status,
'error': error
},
dataType: "text",
crossDomain: true,
success: function(){
location.href = '/wrong';
console.log('go /wrong');
}
});
return;
}
query.php
將 status 和 error 丟到數據庫
怪異的是:確實有順利丟數據庫。但是就是沒有執行 location.href = '/wrong';
跳轉?
這是哪裡有問題?還是說可以有更好的寫法避免這個問題?
根据你的代码,有两种可能:
alert
是同步的,会阻止后面代码的执行,所以没有跳转ajax
返回失败如果你点了
alert
的弹出框没有跳转,就是第二个原因;没点弹出框当然也不会跳转,就是第一个原因。