doufangyan6862 2011-07-25 15:04
浏览 27
已采纳

异步加载来自多个服务器的服务器信息

I have coded a php script that is used to check the status of several different servers, determine if they are online, and then output their version information as well as give the option to update databases on the server.

The problem I'm having is that when the script reaches a server that is offline, it hangs for a very long time while it performs the check. I figured that a good way around this may be to use something like jQuery or XAJAX to load the different servers asynchronously, so that one server doesn't hang the entire script.

I call a single function to begin all of the checks, and echoing of server information:

    outputServerInfo("addressOfServerHere", "nameofServerHere", array("Names", "of", "databases");

My question is: what would be the best method to load these servers asynchronously? If I could get it to say "Loading..." in the place of each server while it performs the checks, that would be ideal. I haven't used jQuery or XAJAX before, so I thought it best to get some input the community. Thanks!

EDIT: I've now got it working and loading all of my servers, but I've got another problem.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">

document.write("<h1>Server Manager</h1><form method='post' name='form1'>");

function server_output(serverName) {
        document.write("<div id=" + serverName + "Loading>Loading " + serverName + "...</div>");
        $.ajax({
        url  : 'serverManager.php',
        async: true,
        type : 'POST',
        data : 'serverName=' + serverName,
        success : function(msg){
            document.write("<div id=" + serverName + "Loading>");
            document.write(msg);
            document.write("</div>");
        }
    });
}
server_output("serverName");
</script>
<input type='SUBMIT' value='GO' name='btnGo' onSubmit=document.form1.submit(); />
<input type='HIDDEN' name='ACTION' value='GO' />

When the I load the page, I can see the Server Manager header, as well as the button that comes after the last tag, however, they disappear almost immediately. The server information loads after that and they don't reappear, so I'm left without my title as well as the button that lets me use my form(my php script creates checkboxes that are used to submit jobs to the servers for updating). Any ideas?

  • 写回答

4条回答 默认 最新

  • dongmou2389 2011-07-25 15:13
    关注

    Well for jQuery it's as easy as calling your backend PHP script.

    $.ajax({
        type : 'POST',
        url : 'your_script.php',
        async : true, //default anyway
        data : '', //server ip, or something to send to the script using type as the method
        success : function(msg){
            //do something here with returned data
            //Example: alert(msg) will show the output results from the backend script
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

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