简体   繁体   English

在jQuery对话框中显示PHP输出。

[英]Show PHP output in jQuery Dialog box.

There is a ping.php file, which is works great on its own: 有一个ping.php文件,该文件非常有用:

Ping the given host, and shows the ping result immediately row by row on a web-page. 对给定的主机执行ping操作,并立即在网页上逐行显示ping结果。

But I would like to show the ping result in a jQuery Dialog box, 但我想在jQuery对话框中显示ping结果,

Similarly, row_by_row. 同样,row_by_row。

Here is the jQuery code: 这是jQuery代码:

  $(function() {
    var tag = $("<div></div>");
    $("#button").on('click', function() {
      $.ajax({
        url: "/modules/ping.php?host=172.16.1.1",
        success: function(data) {
          tag.html(data).dialog({title: 'Ping', modal: false}).dialog('open');
        }
      });
    });
  });

But in this case the Dialog box only appears (and show the result), when the ping.php Completed the run, and I do not see the ping result row by row! 但是在这种情况下,仅当ping.php完成运行时,对话框才会出现(并显示结果),而我却没有一行一行地看到ping结果! This is not good. 不是很好。

Is it possible to fix this? 有可能解决这个问题吗?

I'm assuming ping.php was previously included in an iframe or visited directly? 我假设ping.php以前曾包含在iframe中或直接访问过? This works because the PHP flushes it output to the browser after each ping and the data sent to your computer. 之所以可行,是因为在每次ping之后,PHP都会将其刷新输出到浏览器,并将数据发送到您的计算机。 The browsers holds a constant connection to the server while downloading these results. 下载这些结果时,浏览器与服务器保持稳定的连接。

Note, however, that when using ajax you're using the success callback, which fires when the page has finished loading, this is not compatible with the way your php script works. 但是请注意,当使用ajax时,您正在使用success回调,该回调在页面加载完成时触发,这与您的php脚本的工作方式不兼容。

You're going to have to look at a more complex solution, such as the javascript calling the PHP for each ping (so it can show the progress), or something that relies on websockets to push updates to the browser. 您将不得不考虑一个更复杂的解决方案,例如JavaScript为每个ping调用PHP(以便它可以显示进度),或者依靠websocket将更新推送到浏览器的内容。

More detail can be found in questions like: What is the best way of showing progress on an Ajax call? 在以下问题中可以找到更多详细信息: 显示Ajax调用进度的最佳方法是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM