doraemon0769 2017-10-13 00:37
浏览 28

在浏览器导航之前,让php POST等到页面完成?

This is a complex question so I'll try and be precise.

I've experimented with AJAX but this form requires many changes to do it. I'd like to know if there are other options.

I have a form which takes a very long time to complete. Let's say the form exists on page A. The form submits and calls page B.

Page B looks like this, and gives the incorrect result (the page appears blank while loading):

<html>header</html>
<?php
longformresult()
?>

If I setup the page like this I get the result I am looking for (the page waits until the long function is done to load the page, allowing me to display a loading screen on page A).

<?php
longformresult()
?>
<html>header</html>

however this is where things get really tricky, the longformresult() can fail and break everything below it.

Is there some way I can tell php to wait until the page is fully loaded before sending the page, allowing me to have a loading screen on page A? Or prevent a die() from killing my page? I essentially need to delay the appearance of Page B, and actually just a sleep() is probably the best approach I've had so far:

<?php
sleep(4)
?>
<html>header</html>
<?php
longformresult()
?>

Edit: Conclusion (Not the fix I was looking for though)

I used ajax and removed 'Page B' entirely.

  • 写回答

1条回答 默认 最新

  • duan41497 2017-10-13 00:46
    关注
    1. PHP waits by default to complete the function call before proceeding (see this previous answer), so PHP necessarily waits for the page to be fully loaded before returning.

    2. AJAX would not require "many changes" if this is truly the behavior of the program. You would simply have a new file like C.php which returns the output of longformresult(), which you can later inject into your page.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮