如果用户在AJAX请求结束之前退出浏览器或更改页面会怎样? [英] What happens if a user exits the browser or changes page before an AJAX request is over

查看:117
本文介绍了如果用户在AJAX请求结束之前退出浏览器或更改页面会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过ajax调用php脚本来进行一些数据库维护.如果用户关闭页面,点击或单击链接,PHP脚本会完全执行吗?有办法吗?

I am calling a php script over ajax to do some database maintenance. If the user closes the page, hits back, or clicks a link, will the php script be fully executed? Is there a way to do it?

也许php脚本调用了exec()方法或类似方法,这反过来又会通过控制台这样调用脚本:

Maybe if the php script called the exec() method or something similar, which would in turn call a script via the console as such:

$ php /var/www/httpdocs/maintenance.php

?

推荐答案

只要用户代理(浏览器等)已完全发送了请求,服务器便拥有了它所需要的一切,并将完成请求并尝试发送返回响应.

As long as the user agent (browser, etc.) has fully sent the request, the server has all it needs and will complete the request and try to send back a response.

实际上,这种"ping"行为通常用于使服务保持温暖或执行定期维护的类似心跳"的进程.

In fact, this sort of "pinging" behavior is often used for "heartbeat"-like processes that keep a service warm or perform periodic maintenance.

这篇关于如果用户在AJAX请求结束之前退出浏览器或更改页面会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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