预期页面上的jQuery 1.4.2 IE8错误')'

时间:2010-09-01 06:39:31

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

我遇到了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
            }
            ?>
        });

1 个答案:

答案 0 :(得分:1)

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

您使用的是资产套餐吗?资产包装商中资产如何列出的顺序可能是错误的。