2013-10-03 46 views
-3

我有一個iframe可以在用戶單擊按鈕時從控制面板發送命令。使用下面的代碼時,由於代碼中存在語法錯誤,用戶單擊時該按鈕沒有任何反應。命令中的語法錯誤

$items['googledotcom'] = array 
     (
      'description'=>'DNS resolution test', 
      '1'=>1, 
      '0'=>0, 
      'fixCommand'=>'EXC service network restart; echo "nameserver 8.8.8.8" >> /etc/resolv.conf; sleep 10; health check', 
     ); 

上面的代碼不工作,因爲這條線的,:回聲 「域名服務器8.8.8.8」 >> /etc/resolv.conf中;

但是,當我刪除上面的行代碼將工作。但我還需要添加上面的行。

對語法的任何建議?

謝謝!

UPDATE

命令格式: enter image description here

doCommand的Javascript:

<script type='text/javascript'> 

function doCommand(command) 
{ 
    var r=confirm("Are you sure you want to \"" + command + "\""); 
    if (!r) 
    { 
     return; 
    } 

    $.post('/device/commands-frame/', { id : '<?=$this->site->id;?>', act : command, command : command }, function(data) 
    { 
     alert('Command has been sent'); 
    }); 
} 
</script> 
+0

你怎麼知道這是行不通的? – Phil

+0

當按鈕點擊時,沒有任何反應。否則我會收到警報 – NewPHP

+0

*「沒有任何反應」*不是很有幫助。你有沒有啓用錯誤報告?試圖發出該命令的結果是什麼? – Phil

回答

2

試試這個:

<?php 
$items['googledotcom'] = array 
    (
     'description'=>'DNS resolution test', 
     '1'=>1, 
     '0'=>0, 
     'fixCommand'=>"EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check" 
    ); 
    var_dump($items); 
?> 

這說明:

array(1) { ["googledotcom"]=> array(4) { ["description"]=> string(19) "DNS resolution test" [1]=> int(1) [0]=> int(0) ["fixCommand"]=> string(103) "EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check" } } 

現在我測試用下面的小提琴的價值和它的工作: http://jsfiddle.net/EjXmp/

那搗鼓包含以下代碼:

$(document).ready(function(){ 

$("#clickme").click(function(){ 
doCommand("EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check"); 
}); 

function doCommand(command) 
{ 
var r=confirm("Are you sure you want to \"" + command + "\""); 
if (!r) 
{ 
    return; 
} 

$.post('/device/commands-frame/', { id : '<?=$this->site->id;?>', act : command, command : command }, function(data) 
{ 
    alert('Command has been sent'); 
}); 
} 

}); 
+0

除了添加一些調試之外,這有什麼不同? – Phil

+0

在我的本地主機上測試過,並且正在工作......沒有錯誤......感謝-1;) – Hackerman

+0

OP的代碼如何?那*不起作用*? – Phil