dougou8639 2019-06-06 14:08
浏览 93

如何在没有ajax的情况下提交后执行php脚本?

I am actually using a PHP script that takes some time to execute. It does echo strings every second, for let's say 1 min. What I am trying to do is to "echo" these strings into my HTML page. When I call my function inside my page, it works nicely, it executes when the page loads, and echo a string each second :

<h1> Here is my func </h1>
<?php my_func();?>

But not I'd like to show this when I am sending a form (because I will use the form as parameters of my function). So I tried something like this :

<form method="POST" action="">
  <input name='param' value='param'type='text'/>
</form>
<script>
  $.ajax({
    url:'phpfileWithMyFunc.php',
    data: {
      param : param
    },
    dataType: 'json',
    type:'post'
  )}.done(function (data){
    $('body').append(data);
  });
</script>

This one doesn't work at all, no idea why. So I tried something else, with $.post :

<form method="POST" action="">
  <input name='param' value='param'type='text'/>
</form>
<script>
  $('#form').submit(function () {
    $.post('phpfileWithMyFunc.php', { param: param }, function(result) {
      $('tbody').append(result);
    });
    return false;
   });
</script>

Finally, this one works, but my php file has to finish his execution (waiting 1 minute in my case), to have my results happened.

So I'm here to ask, is there any way to do as I was executing my PHP file "inside" my HTML file, so each time I echo a string it displays instantly on my HTML (every second in my case), instead of waiting for the end of my script?

Thanks for helping.

  • 写回答

1条回答 默认 最新

  • dqsvnsad79721 2019-06-06 14:13
    关注

    No, because php is interpreted in the server and you only get html in your browser.

    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私