-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',
        );

上面的代码不起作用,因为这一行:echo "nameserver 8.8.8.8" >> /etc/resolv.conf;

但是当我删除上面的行时,代码将起作用。但我也需要添加上面的行。

对语法有什么建议吗?

谢谢!

更新

命令格式: 在此处输入图像描述

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>
4

1 回答 1

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');
});
}

});
于 2013-10-03T01:31:22.370 回答