douluanji8752 2014-11-23 15:00
浏览 98

如何将exec输出显示到文本区域

I have a page where on button click, calls a javascript function that executes the following:

 <?php $i = exec('/etc/init.d/iptables status'); ?>

  document.getElementById('txtArea').innerHTML += <?php echo $i; ?>;

but the text area stood empty,
any advice or solution?

  • 写回答

1条回答 默认 最新

  • duanchensou8685 2014-11-23 15:13
    关注

    PHP output into HTML:

    <textarea><?php echo shell_exec('/etc/init.d/iptables status'); ?></textarea>
    

    PHP output into HTML, but in form of a Javascript Value Update on the Textarea element:

    <textarea id="txtArea">...</a>
    <script>
    document.getElementById("txtArea").value = "<?php echo shell_exec('/etc/init.d/iptables status'); ?>";
    </script>
    

    But i doubt, that you want this.

    So, finally the whole thingy again, but now with a button as the trigger for a JS/jQuery Ajax Get request:

    <textarea id="txtArea">...</a>
    
    <input type="button" id="txtAreaUpdateButton" value="Update Textarea"/>
    
    <script>
    $(document).ready(function() {
       $('#txtAreaUpdateButton').click(function() {
          $.ajax({ 
              type: "GET",
              url: "http://www.yoursite.com/request.php",//get response from this file
              success: function(response){ 
                $("textarea#txtArea").val(response); // update textarea with response
            }
          });
       });
    });
    </script>
    

    Here 'request.php' contains:

    <?php echo shell_exec('/etc/init.d/iptables status'); ?>
    

    Keep an eye on the quotes. They are often the source for errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看