AJAX - 在用户更改页面后接收响应 [英] AJAX - Receiving the response after user changes pages

查看:76
本文介绍了AJAX - 在用户更改页面后接收响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所知道的:

当我对我的服务器进行ajax调用时,会创建一个处理程序,发送请求,我的php脚本会收到请求并处理它并且 - 如果我告诉它 - 发回一个响应,我的javascript根据需要解析。我也知道即使用户关闭浏览器或更改页面,php也会继续处理请求(这一切都在服务器端完成,所以为什么不呢?^。^)。

What I know:
When I make an ajax call to my server, a handler is created, the request is sent, my php script receives the request and processes it and--if I tell it to--sends back a response, which my javascript parses as I require. I also know that php will continue to process the request even if the user closes the browser or changes pages (its all being done on the server side, so why wouldn't it? ^.^).

我需要知道的事情:

当用户更改我网站中的网页时,是否会杀死ajax处理程序?例如:用户在mysite.com/foo.php上。他们单击一个向我的服务器发送ajax请求的链接。该请求的响应将显示在foo.php上的div#resp中。然后他们会在收到回复之前导航到mysite.com/bar.php。

What I need to know:
Is the ajax handler killed when the user changes pages within my site? For example: The user is on mysite.com/foo.php. They click a link that sends off an ajax request to my server. The response of that request is to be shown in div#resp on foo.php. They then navigate to mysite.com/bar.php before the response is received.

如果我加载相同的javascript函数并在条上有所需的div#resp元素。 php,调用ajax的javascript函数是否仍然可以从服务器接收响应并将其传递给bar.php上的div#resp,从而显示响应?或者原来的ajax手柄不再可用?如果 在标准的javascript中不再可用,那么jQuery中是否有一些植入可以让我检索响应并在bar.php上显示它?

If I load the same javascript functions and have the needed div#resp element on bar.php, can the javascript function that called the ajax still receive the response from the server and pass it into the div#resp on bar.php, thus showing the response? Or is the original ajax handle no longer available? And if it is no longer available in standard javascript, is there some implantation in jQuery that will allow me retrieve the response and show it on bar.php?

推荐答案

从你所描述的内容来看,没有 - 一旦你导航到另一个页面并导致页面重新加载,你的所有javascript处理程序都会被重新实例化并且原来的那些被破坏。

From what you're describing, no - once you navigate to another page and cause a page reload, all of your javascript handlers are re-instantiated and the original ones destroyed.

这篇关于AJAX - 在用户更改页面后接收响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆