发送ajax请求而不等待回答

我想发一个ajax请求发送一些信息,并在发送后立即(无论我是否收到错误/成功)进行重定向(无需等待服务器响应)

我想知道我是否做了类似的事情

$.ajax({ url:_myurl_, timeout:500, success:function(){document.location= _redirectUrl_}, error: function(){document.location= _redirectUrl_} }) 

会工作正常吗? 添加超时是否会取消我的请求?

根据定义,AJAX是异步的。 只需在ajax块之后添加位置重定向代码,而不是在AJAX内部。

 function dummyAjax(){ $.ajax({ //do something success:function(res){ console.log(res);//chrome try preserve log you'll see this response even after redirection } }); window.location.replace('https://google.com');//this would fire without waiting for ajax response }