如何修复错误"预期的标识符,字符串或数字"

时间:2014-03-13 01:57:53

标签: javascript jquery

我一直在争论这个问题几天,我无法解决这个问题,因为它说错误的行是BLANK。我的JS代码如下:

$(document)
    .ready(
            function() {
                // THE DEBUGGER SAYS THE ERROR IS IN THIS LINE"(script1028
                // expected identifier string or number)".
                $(document).ajaxStart(function() {
                    $('#overlay').show();

                });
                $(document).ajaxStop(function() {

                    $('#overlay').hide();

                });

                var html = "";
                $('#zipcode,#telephone').autotab_magic().autotab_filter(
                        'numeric');

                $("#backtoTopholder").click(function() {
                    window.scrollTo(0, 0);
                })
                preload([ '../img/AjaxLoader.gif' ]);

                $("#startover").click(function() {

                })
                $("#backtoTopholder").hide();

                $(function() {
                    $(window).scroll(function() {
                        if ($(this).scrollTop() > 100) {
                            $('#backtoTopholder').fadeIn();
                        } else {
                            $('#backtoTopholder').fadeOut();
                        }
                    });
                    $('#backtoTopholder a').click(function() {
                        $('body,html').animate({
                            scrollTop : 0
                        }, 800);
                        return false;
                    });
                });
                $(".addressMatch").click(function() {
                    alert("index");
                });

                preload([ '../img/step1.png', '../img/step2.png',
                        '../img/step3.png', '../img/step4.png',
                        '../img/step5.png', '../img/step6.png',
                        '../img/add_to_cart_button_off.png',
                        '../img/add_to_cart_button_on.png' ]);
                $.ajaxSetup({
                    cache : false,
                    global : true
                });

                $("#existingCustomer").change(function() {

                    switch (this.value) {
                    case "No":
                        $("#WTNRow").hide();
                        break;
                    case "Yes":
                        $("#WTNRow").show();
                        break;
                    default:
                        break;
                    }
                })

                $("#plus4")
                        .click(
                                function() {
                                    if (!$("#address").val()
                                            || !$("#city").val()
                                            || !$("#state").val()) {
                                        alert("In order to do verify the zip code you need to fill out the address,city and state");
                                        return false;
                                    }

                                    var data = $("#searchPackages")
                                            .serialize();
                                    var requestZipCode = $
                                            .ajax({
                                                url : "classes/Dispatcher.php?Ziplookup=1",
                                                type : "POST",
                                                dataType : "text",
                                                cache : 'false',
                                                data : data
                                            });

                                    requestZipCode
                                            .success(function(data) {
                                                var result = data;
                                                if ($.trim(result) == "not found") {
                                                    $("#zipCodeReturnmsg")
                                                            .html("");
                                                    $("#zipCodeReturnmsg")
                                                            .html(
                                                                    "<font color=\"red\">could retrieve a valid zipcode, please review your address and try again.Please select a unit Suffix.</font>");
                                                } else {
                                                    $("#zipCodeReturnmsg")
                                                            .html("");
                                                    $("#zipcode")
                                                            .val(
                                                                    $(
                                                                            "#zipcode")
                                                                            .val()
                                                                            + $
                                                                                    .trim(result));
                                                    $("#zipCodeReturnmsg")
                                                            .html(
                                                                    "<font color=\"green\">zip code retrieved successfully.</font>");
                                                }
                                            });
                                    requestZipCode
                                            .fail(function(jqXHR, error,
                                                    errorThrown) {
                                                $("#test").html(
                                                        jqXHR.responseText);
                                            });
                                })

            });

我忽略了额外的逗号和保留词,我相信我没有错过任何。任何帮助解决这个问题都将非常感激。

我起诉jquery版本1.10.2。

非常感谢

2 个答案:

答案 0 :(得分:-1)

缩进使得阅读内容非常困难,我相信你错过了几个分号。例如:

$("#backtoTopholder").click(function(){ window.scrollTo(0,0); }) preload(['../img/AjaxLoader.gif']); 应该是这样的:

$("#backtoTopholder").click(function(){ window.scrollTo(0,0); }); preload(['../img/AjaxLoader.gif']);

答案 1 :(得分:-1)

您在此处发布的内容没有任何问题。您的错误在其他地方。 Fiddly proof here

// some code because Stack Overflow complains to JSFiddle links
// without accompanying code...
// even though I just posted the exact same code that OP did
// only with filler functions to stub for code he did not post
// >.<