2014-03-13 39 views
0

我一直在打击这一问题的几天,我不能够因为它说的错误是行是空白,以解决此问题。我的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。

非常感谢你

+1

你有一个的jsfiddle?祝你好运起诉的jQuery;) – David

回答

-1

缩进使得它很难看发生了什么事情,我相信你错过了几个分号。例如:

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

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

+2

JavaScript不关心在该行的末尾缺少分号。查一查“自动插入分号”(也是混乱它可以选择环境造成)。 – Amadan

-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 
// >.< 
相关问题