javascript - jQuery 1.4.2 IE8 页面出现错误,预期为 ')'

标签 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 次。有什么建议吗?

这也是完整的脚本 block :

        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
            }
            ?>
        });

最佳答案

JSLint 的错误消息“Implied Global”意味着定义的变量缺少“var”定义...这对于 IE8 来说尤其成问题。您需要仔细检查并将“var”添加到列出的行号中(是的,有很多)。

您是否使用 Assets 打包程序?此处 Assets 在 Assets 打包程序中列出的顺序可能有问题。

关于javascript - jQuery 1.4.2 IE8 页面出现错误,预期为 ')',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3615572/

相关文章:

javascript - ionic 模板中的 var 未定义,但 console.log 显示它

jquery - 在 jQuery AJAX 请求中包含嵌套的 HttpPostedFileBase

c# - 单击使用 HttpResponse.WriteFile 下载文件所需的重试

javascript - onclick事件结果消失

自定义html元素上的javascript覆盖

javascript - Url Post 请求 jquery Django

javascript - 编辑表中的行时添加验证

javascript - 纯 CSS 导航栏 :Hover on List not staying

javascript - html 中的只读属性与removeAttribute 不一致

css - 为什么 Internet Explorer 会将我的内容推送到侧边栏下方?