简体   繁体   English

加载页面上没有动作javascript

[英]No action javascript on load page

When I load my page, the js must display a default value : month, The problem is the graphic is not displayed. 当我加载页面时,js必须显示默认值:month,问题是未显示图形。 I must click on month to display the information. 我必须单击月份以显示信息。

In my ajax, console query string : range: month and this code to identified the range. 在我的ajax中,控制台查询字符串: range: month和此代码来标识范围。

  $group = HTML::sanitize($_GET['range']);

  if (empty($group)) {
    $group = 'month';
  }

 switch($group) {
 }

Below the javascript code (plot libray) allowing to display the graphic 在javascript代码下方(图libray),允许显示图形

Thank you 谢谢

<script type="text/javascript">
$('#range a').on('click', function(e) {
    e.preventDefault();

    $(this).parent().parent().find('li').removeClass('active');

    $(this).parent().addClass('active');

    $.ajax({
        type: 'get',
        url: '{$link}?range=' + $(this).attr('href'),
        dataType: 'json',
        success: function(json) {
            if (typeof json['order'] == 'undefined') { return false; }

            var option = {  
                shadowSize: 0,
                colors: ['#9FD5F1', '#1065D2'],
                bars: { 
                    show: true,
                    fill: true,
                    lineWidth: 1
                },
                grid: {
                    backgroundColor: '#FFFFFF',
                    hoverable: true
                },
                points: {
                    show: false
                },
                xaxis: {
                    show: true,
                    ticks: json['xaxis']
                }
            }

            $.plot('#chart-sale', [json['order'], json['customer']], option);   

            $('#chart-sale').bind('plothover', function(event, pos, item) {
                $('.tooltip').remove();

                if (item) {
                    $('<div id="tooltip" class="tooltip top in"><div class="tooltip-arrow"></div><div class="tooltip-inner">' + item.datapoint[1].toFixed(2) + '</div></div>').prependTo('body');

                    $('#tooltip').css({
                        position: 'absolute',
                        left: item.pageX - ($('#tooltip').outerWidth() / 2),
                        top: item.pageY - $('#tooltip').outerHeight(),
                        pointer: 'cusror'
                    }).fadeIn('slow');  

                    $('#chart-sale').css('cursor', 'pointer');      
                } else {
                    $('#chart-sale').css('cursor', 'auto');
                }
            });
        }
    });
});

$('#range .active a').trigger('click');
</script>

error console : 错误控制台:

uncaught TypeError: $.plot is not a function
    at Object.success (index.php:280)
    at c (jquery-3.4.0.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-3.4.0.min.js:2)
    at l (jquery-3.4.0.min.js:2)
    at XMLHttpRequest.<anonymous> (jquery-3.4.0.min.js:2)

line : 行:

        $.plot('#chart-sale', [json['order'], json['customer']], option);

I write the answer just to close the post (you can see the discussion in the question comments) Remember that JavaScript is not compiled so every expression is read top-bottom. 我写答案只是为了关闭帖子(您可以在问题注释中看到讨论)。请记住,JavaScript没有编译,因此每个表达式都是从上至下读取的。 To make sure your functions are recognized by the interpreter you need to give the right order to your scripts. 为了确保您的功能可以被解释器识别,您需要为脚本赋予正确的顺序。 Anyway you could execute your code after the page has been loaded by windows.load = function(){<your_code>} in JavaScript or $(document).ready(function(){<your_code>}) if you're using jQuery library . 无论如何,如果您使用的是jQuery,则可以在JavaScript中通过windows.load = function(){<your_code>}$(document).ready(function(){<your_code>})加载页面后执行代码。图书馆 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM