Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript重新加载php函数_Javascript_Php_Jquery_Ajax - Fatal编程技术网

使用javascript重新加载php函数

使用javascript重新加载php函数,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我使用OO php并通过这个类生成前端页面,我试图重新加载一个按钮,这样一旦按下它,它就会同时更改类和按钮。以下是生成按钮的函数: public static function printStartStopAll($enabled = 'false') { syslog(LOG_INFO, "HELLO"); ?> <div class="big-button-wrapper"> <? if ( is_combined_server

我使用OO php并通过这个类生成前端页面,我试图重新加载一个按钮,这样一旦按下它,它就会同时更改类和按钮。以下是生成按钮的函数:

public static function printStartStopAll($enabled = 'false')
{
    syslog(LOG_INFO, "HELLO");
    ?>
    <div class="big-button-wrapper">
    <?
    if ( is_combined_server() ) {
        // print start all button
        $title_text = dgettext('triplecast', "Start All Transfers");
        $btn_text   = dgettext('triplecast', "Start All");
        if ( !Transfer::CanTransferNow() || count(self::getPendingTransfers()) == 0 ) {
            $class = "big-green-button-off";
            $onclick='';
        } else {
            $class = "big-green-button";
            $onclick = 'onclick=\'startAllTransfers("'.str_replace('"', '\"', self::$txtOpts).'");\'';
        }
        ?>
        <div id='start-all' class='<?=$class?>' title='<?=$title_text?>' <?=$onclick?>><?=$btn_text?></div>
        <?
    }        
    //Separate out the text for readability.
    $title_text = dgettext('triplecast', "Stop Transfers and disable the system till you re-enable it in the configuration menu");
    $btn_text   = dgettext('triplecast', "Stop All");
    $confirm_msg= dgettext('triplecast', 'If you continue all current transfers will be stopped and the system disabled till you re-enable it.');
    $confirm    = dgettext('triplecast', 'Do you want to stop all transfers?');
    ?>
    <div id='stop-all' class='big-red-button' title='<?=$title_text?>' onclick='stopAllTransfers("<?=$confirm_msg.'\n\n'.$confirm?>", "<?=str_replace('"', '\"', self::$txtOpts)?>");'><?=$btn_text?></div>
    <?
    syslog(LOG_INFO, "===>".$enabled);
    if($enabled != "true") {
        $title_text = dgettext('triplecast', "Enable Select");
        $btn_text   = dgettext('triplecast', "Select");
        $class = "big-green-button";
        $onclick='onclick=\'enableSelect(true);\'';
         ?>
        <div id='enable_select' class='<?=$class?>' title='<?=$title_text?>' <?=$onclick?>><?=$btn_text?></div>
        <?
    }
    else {
        $title_text = dgettext('triplecast', "Stop selected Transfers");
        $btn_text   = dgettext('triplecast', "Stop Selected");
        ?>
        <div id='stop-select' class='big-red-button' title='<?=$title_text?>' onclick=''><?=$btn_text?></div>
        <?
    }
    ?>
    </div>
    <?
}
公共静态函数printStartStopAll($enabled='false')
{
系统日志(日志信息,“你好”);
?>
>

你必须使用ajax调用来获得响应并更新HTML。你是想说你从php生成了整个HTML?你这么做的原因是什么?在我开始开发该产品之前就是这样的……相信我,我不喜欢它,但我们生产的每一个产品都是这样的。请关注@PitchInner所说的,因为这就是为什么您的问题是关于。我没有看到ajax响应发生任何变化。
function enableSelect(value)
{
$.getJSON("ajax_requests/enableSelect.php", { enabled: value },
    function(data){
});
}

<?php
$requireAuthentication = false;
$requireLicensing = false;
$minimalIncludes = true; 
require_once('../Library.php');
header('content-type: application/json');

$enabled = getParameter('enabled');
$dist_server = TriplecastConfig::get('distribution_server');
$resp = new TriplecastMsg();


try {
TransferController::setSelectEnabled($enabled);
TransferController::printStartStopAll($enabled);
} catch (Exception $e) {
$resp->setCode(STATUS_ERROR);
$resp->setMessage($e->getMessage());
}

$json = new JSON();
echo $json->encode( array("code" => $resp->getCode(), "message" => $resp->getMessage())