简体   繁体   English

Ajax请求不会在页面重定向上中止

[英]Ajax request not aborted on page redirect

I am sending ajax request on particular page. 我在特定页面上发送ajax请求。 and i click on another link. 然后我单击另一个链接。 and response of ajax request is not come. 并且ajax请求的响应没有到来。 there is any way to not destroy my ajax request on click on any other link. 没有任何方法可以在点击任何其他链接时不破坏我的ajax请求。

If the user leaves the page, there's not much you can do about that. 如果用户离开页面,那么您将无能为力。 You can try to discourage them from leaving, or show an overlay on your page and prevent the user from clicking links on the displayed page (at least until your ajax response arrives). 您可以尝试阻止它们离开,或者在页面上显示覆盖图,并阻止用户单击所显示页面上的链接(至少直到ajax响应到达为止)。 Make sure they understand that leaving the page before their operation is complete may cause problems. 确保他们了解在操作完成之前离开页面可能会导致问题。

If I understand your question correctly, it sounds like you're firing off an ajax request, but then clicking on another link on a page, and so the ajax request never completes? 如果我正确理解了您的问题,听起来您是在发出ajax请求,但是随后单击页面上的另一个链接,那么ajax请求永远不会完成?

If that's the case you could bind a function to all links that would .preventDefault() and then when the AJAX request is complete, you could unbind that function. 如果是这种情况,您可以将一个函数绑定到所有会链接到.preventDefault()链接,然后在AJAX请求完成时,可以取消绑定该函数。

Something along the lines of: 类似于以下内容:

function makeAJAXRequest(){
    $('a').click(function(){});
    //Do AJAX Request Here
}
function AJAXCallbackk(){
    $('a').unbind('click');
    //Parse AJAX here
}

You could also bind a function to onBeforeUnload that would create a window.confirm() which could prompt the user to ask if they are sure you want to leave a page. 您还可以将一个函数绑定到onBeforeUnload ,该函数将创建一个window.confirm() ,提示用户询问他们是否确定要离开页面。 Many websites do this if an input box has unsubmitted text. 如果输入框包含未提交的文本,则许多网站都会这样做。 Facebook is an obvious example. Facebook是一个明显的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM