未捕获的SyntaxError:意外的令牌 - 某些浏览器出错

时间:2017-07-09 10:09:07

标签: jquery ajax

我遇到以下代码问题。 Chrome,Firefox和Opera没有任何问题。但它在Maxthon浏览器,一些移动和电视浏览器上都没有显示。我在Maxthon浏览器的控制台中出现此错误:Uncaught SyntaxError:Unexpected token =

我的代码在这里:

                                    <div class="SerieSeaons">
                                    <div class="seasons-link filters-button-group">
                                        <?php $s= 1; foreach ($seasons as $season) {
                                            ?>
                                            <a class="seasonlink <?php if($s == 1) { echo 'active'; } else { echo 'notloaded'; }?>" href="JavaScript:void(0);"
                                               data-filter=".<?php echo $season->slug; ?>"><?php echo $season->name; ?></a>
                                            <?php $s++; } ?>
                                    </div>
                                    <div class="el-item title sort-by-button-group button-group">
                                        <div class="sortitem status" data-sort-value="status">Watched</div>
                                        <div class="season-name">Season</div>
                                        <div class="sortitem episode-name hidden-xs" data-sort-value="episodename">Episode</div>
                                        <div class="sortitem e-name" data-sort-value="ename">Episode Name</div>
                                        <div class="sortitem date hidden-xs" data-sort-value="date">Air Date</div>
                                    </div>
                                    <div class="psscroll" style="height:100%">
                                        <div class="all-seriespart">
                                            <div class="asisotope" id="rp_<?php echo esc_attr($rp_id); ?>"></div>
                                        </div>
                                    </div>
                                </div>

JavaScript:

jQuery.noConflict();
                                        jQuery(document).ready(function ($) {
                                            "use strict";
                                            var open_category = ".<?php echo $seasons[0]->slug;?>";
                                            function get_blog_posts(this_obj = "<?php echo $seasons[0]->slug;?>") {
                                                $.ajax({
                                                    type: "POST",
                                                    url: mixajaxurl,
                                                    data: "action=get_series_episodes&category="+ this_obj,
                                                    success: function (result) {
                                                        var $newItems = $(result);
                                                        $("#rp_<?php echo esc_js($rp_id); ?>").isotope('insert', $newItems, function () {
                                                            $("#rp_<?php echo esc_js($rp_id); ?>").ready(function () {
                                                                $("#rp_<?php echo esc_js($rp_id); ?>").isotope('layout');
                                                            });
                                                            $("#rp_<?php echo esc_js($rp_id); ?>").isotope('layout');
                                                            $("#rp_<?php echo esc_js($rp_id); ?>").isotope({
                                                                getSortData: {
                                                                    status: '[data-watched]',
                                                                    episodename: function( itemElem ) {
                                                                        var weight = jQuery( itemElem ).find('.dataepisode').text();
                                                                        return parseFloat( weight.replace( /[\(\)]/g, '') );
                                                                    },
                                                                    ename: '.e-name',
                                                                    date: '.date'
                                                                }
                                                            });
                                                            $(window).trigger('resize');
                                                        });
                                                        $("#rp_<?php echo esc_js($rp_id); ?>").removeClass('loading');

                                                    }
                                                });
                                            }
                                            function watch_alls(cat_slug = "<?php echo $seasons[0]->slug;?>") {
                                                $.ajax({
                                                    type: "POST",
                                                    url: mixajaxurl,
                                                    data: "action=watch_to_all&category="+ cat_slug,
                                                    success: function (result) {
                                                        $('.watchallwrap').html(result)
                                                    }
                                                });
                                            }
                                            var filterFns = {
                                                ium: function () {
                                                    var name = jQuery(this).find('.name').text();
                                                    return name.match(/iumjQuery/);
                                                }
                                            };
                                            $(".seasons-link").on("click",".notloaded", function(){
                                                $("#rp_<?php echo esc_js($rp_id); ?>").addClass('loading');
                                                open_category = $(this).data('filter');
                                                get_blog_posts(open_category);
                                                watch_alls(open_category);
                                                $(window).trigger('resize');
                                                var filterValue = jQuery(this).attr('data-filter');
                                                filterValue = filterFns[filterValue] || filterValue;
                                                $('.asisotope').isotope({
                                                    itemSelector: '.ajax_post',
                                                    layoutMode: 'fitRows',
                                                    filter: filterValue
                                                });
                                                jQuery(this).removeClass('notloaded');
                                                return false;
                                            });

                                            jQuery('.seasons-link').each(function (i, buttonGroup) {
                                                var jQuerybuttonGroup = jQuery(buttonGroup);
                                                jQuerybuttonGroup.on('click', 'a', function () {
                                                    jQuerybuttonGroup.find('.active').removeClass('active');
                                                    $(this).addClass('active');
                                                    $('.psscroll').scrollTop(0);
                                                    $('.psscroll').perfectScrollbar('update');
                                                });

                                            });

                                            $(window).load(function () {
                                                $("#rp_<?php echo esc_js($rp_id); ?>").addClass('loading');
                                                get_blog_posts();
                                                watch_alls("<?php echo $seasons[0]->slug;?>");
                                                $('.asisotope').isotope({
                                                    itemSelector: '.ajax_post',
                                                    layoutMode: 'fitRows'
                                                });

                                                function watchblog() {
                                                    $(".asisotope").isotope({
                                                        itemSelector: '.ajax_post',
                                                        layoutMode: 'fitRows'
                                                    });
                                                }
                                                setInterval(watchblog, 100);
                                            });
                                        });

1 个答案:

答案 0 :(得分:0)

您正在使用ES6 default function parameters,这是最近才支持的浏览器。

要么您不使用这些语言功能,要么设置Babel之类的内容,以便将代码转换为兼容代码。

这是您的默认参数代码

function multiply(a, b = 1) {
    return a * b;
}

这也可以在旧浏览器中使用

function multiply(a, b) {
    b = (typeof b !== 'undefined') ?  b : 1;
    return a * b;
}