【问题标题】:jQuery 1.4.2 IE8 error on page expected ')'预期页面上的 jQuery 1.4.2 IE8 错误“)”
【发布时间】:2010-09-01 06:39:30
【问题描述】:

我在使用 IE8 时遇到问题(那里没有什么新东西)。我得到的错误没有多大意义,因为它不会发生在 FF 或 Chrome 上。代码如下:

function remComp(id, trade) {
            $.ajax({
                url: "functions/removePriceSurveyComparison.php",
                type: "POST",
                async: true,
                data: "id="+id,
                dataType: "xml",
                success: function(xmlData) {
                    if ($("success", xmlData).text() == "true") {
                        loadComps(trade);
                    }// TODO create error handler
                }
            });
        }

在此函数中,它抱怨定义成功回调的行。这个函数甚至还没有被调用呢?但是当它被调用时,它工作得很好,尽管仍然会产生新的错误?

被调用的函数是:

        function loadComps(trade) {
            $.ajax({
                url: "functions/loadPriceSurveyComparisons.php",
                type: "POST",
                async: true,
                data: "trade="+trade,
                cache: false,
                dataType: "html",
                success: function(comps) {
                    $("#current"+trade).html(comps);
                }
            });
        }

第二个函数基本上在页面加载时被调用了 3 次。有什么建议吗?

这里也是完整的脚本块:

        function remComp(id, trade) {
            $.ajax({
                url: "functions/removePriceSurveyComparison.php",
                type: "POST",
                async: true,
                data: "id="+id,
                dataType: "xml",
                success: function(xmlData) {
                    if ($("success", xmlData).text() == "true") {
                        loadComps(trade);
                    }// TODO create error handler
                }
            });
        }

        function addComp(trade, albId, compId) {
            $.ajax({
                url: "functions/addPriceSurveyComparison.php",
                type: "POST",
                async: true,
                data: "trade="+trade+"&albId="+albId+"&compId="+compId,
                cache: false,
                dataType: "xml",
                success: function(xmlData) {
                    if ($("success", xmlData).text() == "true") {
                        loadComps(trade);
                    }// TODO add an error handler
                }
            });
        }

        function updateComp(id, trade) {
            var albId = $("select#albProd"+id).val();
            var compId = $("select#compProd"+id).val();

            $.ajax({
                url: "functions/updatePriceSurveyComparison.php",
                type: "POST",
                async: true,
                data: "id="+id+"&albId="+albId+"&compId="+compId,
                cache: false,
                dataType: "xml",
                success: function(xmlData) {
                    if ($("success", xmlData).text() == "true") {
                        // reload table for this trade
                        loadComps(trade);
                    }// TODO create error handler
                }
            });
        }

        // function that loads all of the comparisons for a specific trade
        function loadComps(trade) {
            $.ajax({
                url: "functions/loadPriceSurveyComparisons.php",
                type: "POST",
                async: true,
                data: "trade="+trade,
                cache: false,
                dataType: "html",
                success: function(comps) {
                    $("#current"+trade).html(comps);
                }
            });
        }

        // define document.ready function
        $(document).ready(function() {
            // load all of the comparisons for each trade
            <?php
            foreach ($trades as $trade) {
                echo "loadComps(\"$trade\");\n";
                ?>
                $("#addComp<?php echo $trade; ?>").click(function(e) {
                    e.preventDefault();
                    addComp("<?php echo $trade; ?>", $("#albProd<?php echo $trade; ?>").val(), $("#compProd<?php echo $trade; ?>").val());
                });
                <?php
            }
            ?>
        });

【问题讨论】:

  • 这对我来说看起来非常好。而且我已经戴上了支架规格。
  • 呵呵,是的,但是 IE8 令人头疼,而且显然在页面上出现实际上并没有做任何事情的错误是不可接受的......
  • 页面上还有其他脚本吗?
  • 这没有错。其他地方一定有错误。您是否尝试过通过 jslint 运行所有代码?
  • 好的,用完整的脚本块更新了帖子。在 $(document).ready 块中,您会注意到一些 PHP,它基本上打印了 loadComp 函数,该函数被调用的次数与“交易”相同。 jslint我还没试过,现在看看,谢谢。

标签: javascript jquery internet-explorer internet-explorer-8


【解决方案1】:

JSLint 的错误消息“隐含全局”意味着定义的变量缺少“var”定义……这对于 IE8 尤其成问题。您需要通过并将“var”添加到列出的行号(是的,有很多)。

您使用的是资产打包器吗?资产在资产打包器中的列出顺序可能有问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-03
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多