【问题标题】:PHP script output through javascript on webpage通过网页上的 javascript 输出 PHP 脚本
【发布时间】:2017-04-21 05:26:47
【问题描述】:

我正在尝试构建一个带有导航栏菜单和子菜单的网页,单击它会在 index.html 中运行一个函数并调用一个调用 php 脚本的 ajax 函数。 php 脚本依次调用 windows 批处理文件,该批处理文件调用 powershell 脚本。

我正在尝试设计它,以便在我单击子菜单项后,ajax 函数调用 php 脚本并运行 powershell 脚本。在我单击子菜单项以显示它正忙/加载或正在处理请求后,我还需要来自网页的某种反馈,然后是完成处理后的 php 脚本的结果。所有这一切,而我仍然保持导航栏和顶部的子菜单完好无损。

我的问题是,

  1. 我得到一个弹出警报窗口,我认为这是因为我的 t1 () ajax 函数中的警报(结果)。如何使其成为网页显示?

2.最后调用powershell脚本的php脚本没有得到任何输出。

任何帮助表示赞赏!

我的 index.html 在下面

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.dropdown-submenu {
position: relative;
}

.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
@media (min-width: 979px) {
ul.nav li.dropdown:hover > ul.dropdown-menu {
display: block;
}
}
ul.nav li.dropdown-submenu:hover > ul.dropdown-menu {
display: block;
}
</style>
</head>
<body>

<div class="navbar navbar-inverse ">
<div class="container-fluid">


        <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">VMware VC Reports</a>
        </div>

                <div class="collapse navbar-collapse" id="myNavbar">
    <ul class="nav navbar-nav">
    <li class="dropdown"><a class="dropdown" data-toggle="dropdown" href="#">Vcenters<span class=caret></span></a>

        <ul class="dropdown-menu">

    <li class="dropdown-submenu">
        <a class="test" tabindex="-1" href="#">San Jose Vcenter<span class="caret"></span></a>
        <ul class="dropdown-menu">
        <li><a tabindex="-1" onclick="t1()">ESX Info</a></li>
        </li>
        </ul>

        </li>
        </ul>
    </ul>
                </div>
</div>
</div>

<script>
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
</script>

<script>
function t1 () {
  $.ajax({
    url:"t1.php",
    type: "POST",
    success:function(result){
     alert(result);
   }
 });
}
</script>
</body> 
</html>

我的 t1.php 在下面。

 <?php
 echo "Loading...";
 system("t1.bat");
 echo '<meta http-equiv="refresh" content="1; URL=t1.html" />';
 exit;
 ?>

我的 t1.html 在下面。它几乎包含了所有的 index.html,这部分添加在底部

ti.html

<script type="text/javascript">
<!--
var iframe = document.createElement("iframe");
iframe.src = "t1.txt";
iframe.width = "20000";
iframe.height = "20000";
iframe.frameBorder = "0";
iframe.scrolling = "no";
document.body.appendChild(iframe);
//-->
</script>

【问题讨论】:

    标签: php jquery html ajax powershell


    【解决方案1】:

    而不是警告来自 php 的 php 将其附加到 html div。

    success:function(result){
    $('#anydiv').html(result); 
    }
    

    请多解释一下:“我没有从最后调用 powershell 脚本的 php 脚本得到任何输出。”

    【讨论】:

    • php 脚本 ';出口; ?> 调用批处理文件 t1.bat....就像这样 Powershell.exe -executionpolicy remotesigned -File C:\xampp\htdocs\view\test\t1.ps1 > "C:\xampp\htdocs\view\ test\t1.txt"....它正在调用一个 powershell 脚本...我没有将此 powershell 脚本的任何输出返回到网页。
    • $('#anydiv').html(result); index.html 或其他地方的任何 div 名称?
    • 好吧,因为&gt; "C:\xampp\htdocs\view\test\t1.txt" 正在将 PowerShell 脚本的输出重定向到文件 t1.txt
    • 我完全删除了重定向,仍然是一个空白页面。
    猜你喜欢
    • 2018-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多