我有一个包含这些文件的PHP应用程序:landing.php,redirect.php在页面调用,ajax.phpPHP usleep /睡眠
到landing.php,我执行JavaScript代码捕获某些数据,并发布AJAX POST到ajax.php,将它们插入到数据库中。最后PHP的header()函数重定向到redirect.php
目前上述功能是通过输出缓冲,但header()函数太快,所述AJAX POST不finished..ie执行时,没有数据库查询已完成。
我尝试使用睡眠()usleep()函式之前头(),但他们没有工作。由于我对输出缓冲不是很熟悉,请您提供一种友好的手?
谢谢。
<?php ob_start(); ?>
<scripts type="text/javascript">
var data = 'blah..blah..blah..';
ajaxPost('ajax.php', data);
</scripts>
<?php
sleep(2); // <---- I want the script to sleep here and wait for the AJAX to finish
header('c.php)
ob_end_flush();
?>
有没有理由通过AJAX调用来保存东西?如果您想先将数据保存到数据库然后重定向,为什么不在PHP脚本中完成所有操作?无论如何,这是明显的方法。 :) – Rytmis 2009-08-03 10:33:32