尝试加载" DIV"动态内容被返回 [英] Attempting to load a "div" as dynamic content is returned

查看:143
本文介绍了尝试加载" DIV"动态内容被返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP程序,该程序执行了一系列关键驱动SSH连接(如Apache用户WWW的数据),并执行其检查的一对夫妇服务/守护程序的状态在远程服务器上的脚本。基于所报告的状态,运行或停止的函数确定适当的图像,绿色的支票或红色的x,这应该是一个div表格单元内的显示。

I have a PHP program which performs a series of key driven SSH connections (as Apache user www-data), and executes scripts on the remote server which check the statuses of a couple services/deamons. Based on the reported status, "Running" or "Stopped," a function determines the appropriate image, green check or red 'x', that should be display within a div table cell.

这看起来是这样的:

现在的问题是9服务器轮询和18格表格单元格的动态建立。我想刷新/显示每个分区的数据是从每个SSH调用返回。

The problem is 9 servers are polled and 18 div table cells are dynamically built. I'd like to refresh/display each div as the data is returned from each SSH call.

这是PHP code其中每个SSH调用时包含结果的DIV插入:

This is the PHP code where each SSH call is made the div containing the result is inserted:

           $cmd_string=buildServiceCallString($distIP, "VolCreationService","serviceCheck");

            echo "<div class=\"statTableRow\">";
        echo "<div class=\"statData statTableCell\">";
            $cmd_output=shell_exec($cmd_string);
            echo "<span class=\"serviceTitle\">VolCreationService: <img class=\"runStatImage\" src=\"".displayRunStatusImage($cmd_output)."\"></span>";
            $cmd_output="";
                   echo "</div>"; //end statTableCell
                   echo "</div>"; //end statTableRow

我已经做出了努力,了解jQuery的.load()方法,但它没有点击呢。我想这将涉及一个回调,但我不明白这个元素如何访问和异步调用显示出来。

I've made an effort to understand the jQuery .load() method, but it hasn't clicked yet. I imagine this will involve a callback, but I don't understand how the element is accessed and displayed with an asynchronous call.

任何意见大大AP preciated!

Any advice is greatly appreciated!

-TU

推荐答案

因此​​,一个很简单的如何动态内容添加到DOM元素的例子。您可以使用$阿贾克斯

So a very simple example of how to dynamically add content to a DOM element. You can use $.ajax

 var request = $.ajax({
      type: "POST",
      url: "example.php",
      data: data_obj,
      dataType: "html"
   }).done(function(msg) {
         $("#example_element").append(msg);
      }

网址:将指向您的文件

the url: will point to your file.

数据:是可选的,但使用该选项将允许您通过您要检索后面的关键

data: is optional, but using that option will allow you to pass the key you want to retrieve back.

数据类型:指定何种类型的返回你期望

dataType: specifies what return type you expect

在.done你可以做加载内容的最简单的事情就是将其追加的东西(或更换,但在你的情况,你可能要追加的话)。

in .done the simplest thing you can do to load content is just to append it to something (or replace, but in your case you probably want to append it).

请注意,这个调用不检查错误情况。

Note that this call doesn't check for error cases.

该文档是pretty的冗长,但你还是应该读它,如果你打算使用AJAX调用。

这篇关于尝试加载&QUOT; DIV&QUOT;动态内容被返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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