首页 > 解决方案 > yii2:为什么我的注册 js 不能在 heroku 中工作?

问题描述

我有一个问题.. 我正在为健身房培训课程预订申请,这是我的课程结束项目。

我的问题是我有一个可以在本地完美运行的脚本,但是当我更改环境并在 Heroku 上测试我的代码时,它不起作用。

我认为camelsCase或类似的东西一定有问题。因为我找不到错误的解释。顺便说一句,当我按下导航日期的按钮时,我的部分脚本在 Heroku(数字更改)中正常工作。

<?php
$script = <<< JS
    $(document).ready(function(){
        var allcount = Number($('#all').val());
        if(allcount < 10)
        {
            $("#btn-load-more").text("No hay más sesiones disponibles...");
        }
        // Load more data
        $('#btn-load-more').click(function(){
            applyFilter();
        });
        $('#btn-change-date').click(function(){
            var popup =$(this).offset();
            var popupTop = popup.top - 20;
            var popupLeft = popup.left ;
            $('.datepicker.datepicker-dropdown').css({
              'top' : popupTop,
              'left' : popupLeft
             });
        });
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth()+1;
        var prevDay = parseInt(day) - 1;
        var prevMonth = date.getMonth()+1;
        if(prevDay < 1)
        {
            var substractedDate = substractDate(date, 0, -1, 0);
            var prevDay = new Date(substractedDate.getYear(), substractedDate.getMonth() + 1, 0);
            prevDay = prevDay.getDate();
            var prevMonth = substractedDate.getMonth()+1;
            //console.log(prevDay+'/'+prevMonth);
        }
        var nextDay = parseInt(day) + 1;
        $('.btn-prev-date').html('< '+prevDay + '/' + prevMonth);
        $('.btn-next-date').html(nextDay + '/' + month + ' >');
        $('.training-session-heading').html(day+'/'+month);
        $(document).on("click", ".btn-view-description", function(){
            var id = $(this).data('id');
            var href = $(this).data('href');
            $.ajax({
                type: 'get',
                url: href,
                data: {id: id},
                success: function(response){
                    if(response != '')
                    {
                        $("#session-description-modal .modal-content").html(response);
                        $("#session-description-modal").modal('show');
                    }
                }
            })
        });
    });
 JS;
 $this->registerJs($script);
 ?>
<script>
function substractDate(input, days, months, years) {
    return new Date(
      input.getFullYear() + years, 
      input.getMonth() + months, 
      Math.min(
        input.getDate() + days,
        new Date(input.getFullYear() + years, input.getMonth() + months + 1, 0).getDate()
      )
    );
}
function applyFilter(isFilterApplied = false)
{
    var row = Number($('#row').val());
    var allcount = Number($('#all').val());
    var rowperpage = 10;
    if(!isFilterApplied)
    {
      row = row + rowperpage;  
    }
    else
    {
      row = 0;
    }
    var current_day = $("#current_day").val();
    if(row <= allcount){
        $("#row").val(row);
        $.ajax({
            url: $("#get_more_sessions").val(),
            type: 'post',
            data: {row:row,gym_id:$("#gym_id").val(),current_day: current_day, _csrf : $("#csrf_token").val()},
            beforeSend:function(){
                $("#btn-load-more").text("Cargando...");
            },
            success: function(response){
                // pequeño delay mientras se agregan las clases
                setTimeout(function() {
                    // agrega clases después de la última
                    if(isFilterApplied)
                    {
                      $("#session-container").html(response).show().fadeIn("slow");
                    }
                    else
                    {
                      $(".session-item:last").after(response).show().fadeIn("slow");  
                    }
                    if(!isFilterApplied)
                    var rowno = row + rowperpage;

                    // detecta si el valor de las filas es más grande que allcount o no
                    if(rowno >= allcount || response == ''){

                        // cambia el texto y el background
                        $("#btn-load-more").text("No hay sesiones disponibles...");
                        $("#btn-load-more").css("background","darkorchid");
                    }else{
                        $("#btn-load-more").text("Cargar más");
                    }
                }, 2000);
            }
        });
    }
}
function prevNextDate(type)
{
    var currentDay = $("#current_day").val();
    var date = new Date(currentDay);
    if(type == 'prev')
    {
        date = substractDate(date, -1, 0, 0);
    }
    else
    {
        var nextDay = date.setDate(date.getDate() + 1);
        date = new Date(nextDay);
    }
    //console.log(date);
    var day = date.getDate();
    var month = date.getMonth()+1;
    var prevDay = parseInt(day) - 1;
    var prevMonth = date.getMonth()+1;
    var year = date.getFullYear();
    if(prevDay < 1)
    {
        var substractedDate = substractDate(date, 0, -1, 0);
        var prevDay = new Date(substractedDate.getYear(), substractedDate.getMonth() + 1, 0);
        prevDay = prevDay.getDate();
        var prevMonth = substractedDate.getMonth()+1;
        //console.log(prevDay+'/'+prevMonth);
    }
    var nextDay = date.setDate(date.getDate() + 1);
    date = new Date(nextDay);
    var nextDay = date.getDate();
    var nextMonth = date.getMonth()+1;
    $('.btn-prev-date').html('< '+prevDay + '/' + prevMonth);
    $('.btn-next-date').html(nextDay + '/' + nextMonth + ' >');
    $('.training-session-heading').html(day+'/'+month);
    $("#current_day").val(year+'-'+month+'-'+day)
    applyFilter(true);
}
</script>

这是浏览器中出现的错误

在此处输入图像描述

标签: javascriptphpherokuyii2

解决方案


问题不在脚本中,问题在于类名中的拼写错误。显然,语言环境更灵活并接受这些类型的错误,但 heroku 无法接受。

感谢您的关注。


推荐阅读