1
...
success: function (reqCode) {
            if (reqCode['error_code'] == 1) {
                //Generiere Tabelle     
                $(".done").html( 
                    '<p class="bold center"><?php echo "Besucher ".$month_name[' + reqCode['month'] + ']." ".' + reqCode['year'] + '; ?></p>'
                    '<canvas id="cvs" width="680" height="250">[No canvas support]</canvas>'
                    '<script>'
                        'chart = new RGraph.Line("cvs", ' + reqCode['data_string'] + ');'
                        'chart.Set("chart.tooltips", ' + reqCode['labels_string'] + ');'
                        'chart.Set("chart.tooltips.effect", "expand");'
                        'chart.Set("chart.background.grid.autofit", true);'
                        'chart.Set("chart.gutter.left", 35);'
                        'chart.Set("chart.gutter.right", 5);' 
                        'chart.Set("chart.hmargin", 10);' +
                        'chart.Set("chart.tickmarks", "circle");'
                        'chart.Set("chart.labels", ' + $reqCode['labels_tooltip'] + ');'
                        'chart.Draw();'
                    '</script>'
                );      
                $('.done').fadeOut('slow'); 
                $('.done').fadeIn('slow');
            }   
}   

我不知道为什么每条新线都需要自己的'..'。无论如何,它不起作用。查看了 API 参考,但没有发现任何有用的东西:(

编辑:对于我的第二个问题:

这是 JSON 响应:

$response['error_code'] = '1'; 
    $response['data_string'] = "[" . join(", ", $data) . "]";
    $response['labels_string'] = "['" . join("', '", $labels) . "']";
    $response['labels_tooltip'] = "['" . join("', '", $data) . "']";
    $response['month'] = $month_name[$month];
    $response['year'] = $year;

    echo json_encode($response);
4

4 回答 4

2

<script>该标签似乎确实有问题,但真的吗?您不需要插入该<script>标签。你已经在运行 JavaScript;这样做:

success: function (reqCode) {
    if (reqCode['error_code'] == 1) {
        var month_name = <?php echo json_encode($month_name); ?>;
        //Generiere Tabelle     
        $(".done").html( 
            '<p class="bold center">Besucher ' + month_name[reqCode['month']] + ' ' + reqCode['year'] + '</p>'+
            '<canvas id="cvs" width="680" height="250">[No canvas support]</canvas>'
        );

        var chart = new RGraph.Line("cvs", reqCode['data_string']);
        chart.Set("chart.tooltips", reqCode['labels_string']);
        chart.Set("chart.tooltips.effect", "expand");
        chart.Set("chart.background.grid.autofit", true);
        chart.Set("chart.gutter.left", 35);
        chart.Set("chart.gutter.right", 5); 
        chart.Set("chart.hmargin", 10);
        chart.Set("chart.tickmarks", "circle");
        chart.Set("chart.labels", reqCode['labels_tooltip']);
        chart.Draw();

        $('.done').fadeOut('slow'); 
        $('.done').fadeIn('slow');
    }   
}   

我已经修复了一些语法错误,但我不能保证没有任何语法错误。只需观察 JavaScript 控制台是否有错误。

于 2012-05-24T23:50:07.043 回答
1

您应该有一个带有类的容器元素,例如:

<div class="done" />

此外,您可以做空:

$('.done').html('..all the html..').fadeOut('slow').fadeIn('slow');

此外,正如 Vivin Paliath 所说,您应该使用 + 连接 html 中的所有字符串

'<a>'+
'asdsad'+
'</a>'

祝你好运!

于 2012-05-24T23:44:43.450 回答
1

你需要+号


success: function (reqCode) {
            if (reqCode['error_code'] == 1) {
                //Generiere Tabelle     
                $(".done").html('<p class="bold center"></p>'+
                    '<canvas id="cvs" width="680" height="250">[No canvas support]'+
                    '<script>'+
                        'chart = new RGraph.Line("cvs", ' + reqCode['data_string'] + ');'+
                        'chart.Set("chart.tooltips", ' + reqCode['labels_string'] + ');'+
                        'chart.Set("chart.tooltips.effect", "expand");'+
                        'chart.Set("chart.background.grid.autofit", true);'+
                        'chart.Set("chart.gutter.left", 35);'+
                        'chart.Set("chart.gutter.right", 5);' +
                        'chart.Set("chart.hmargin", 10);' +
                        'chart.Set("chart.tickmarks", "circle");'+
                        'chart.Set("chart.labels", ' + $reqCode['labels_tooltip'] + ');'+
                        'chart.Draw();'+
                    ''
                );      
                $('.done').fadeOut('slow'); 
                $('.done').fadeIn('slow');
            }   
}  
于 2012-05-24T23:47:33.343 回答
0

您需要将单个字符串传递给html()函数。就像是:

$(".done").html("<p>hello</p><p>goodbye</p>").

如果您需要组合多个字符串,则需要使用字符串连接,例如:

var combinedString = '<p>hello</p>' + '<p>goodbye</p>'
于 2012-05-24T23:45:47.787 回答