使用php从html执行脚本

时间:2014-09-11 11:43:10

标签: javascript php python html

我有使用javascript调用PHP文件的以下HTML

 <html>
 <head>
 <script type="text/javascript" src="jquery.min.js"></script>
 <script type="text/javascript">
    function doSomething() {
       $.get("mySample.php");
       return false;
     }
 </script>
 <body class="page_bg">
 <a href="#" onclick="doSomething();">Click Me!</a></head>
 </body>
 </html>

当它被执行时,它应该调出&#34; mySample.php&#34;脚本,其代码如下所示

 <?php
 #if ($_GET['run']) 
 {
  # This code will run if ?run=true is set.
   exec("python visualization.py");
 }
 ?>

然后这段代码调用了名为visualization.py的python脚本,这会导致some.html文件,我想在浏览器中找回它。

  1. 鉴于上述方法无效
  2. 这是对的吗?

2 个答案:

答案 0 :(得分:1)

如果您想在通话时显示数据,则需要处理您收到的回复。我认为这会奏效:

$.get("mySample.php", function(resp){
    $('body').html(resp);
});

你测试过你的php文件是否有效?

答案 1 :(得分:1)

试试这段代码:

$.get( "mySample.php", function(data) {
  $('body').html(data);
  alert( "Load was performed." );
});

更多细节:http://api.jquery.com/jquery.get/