JavaScript error (Uncaught SyntaxError: Unexpected end of input)

后端 未结 11 2082
天命终不由人
天命终不由人 2020-11-27 10:30

I have some JavaScript code that works in FireFox but not in Chrome or IE.

In the Chrome JS Console I get the follow error:

\"Uncaught Synta

相关标签:
11条回答
  • 2020-11-27 10:53

    Add a second });.

    When properly indented, your code reads

    $(function() {
        $("#mewlyDiagnosed").hover(function() {
            $("#mewlyDiagnosed").animate({'height': '237px', 'top': "-75px"});
        }, function() {
            $("#mewlyDiagnosed").animate({'height': '162px', 'top': "0px"});
        });
    MISSING!
    

    You never closed the outer $(function() {.

    0 讨论(0)
  • 2020-11-27 10:55

    This error is mainly caused by empty returned ajax calls, when trying to parse an empty JSON.

    To solve this test if the returned data is empty

    $.ajax({
        url: url,
        type: "get",
        dataType: "json",
        success: function (response) {
    
            if(response.data.length == 0){
                // EMPTY
            }else{
                var obj =jQuery.parseJSON(response.data);
                console.log(obj);
            }
        }
    });
    
    0 讨论(0)
  • 2020-11-27 10:58

    Formatting your code a bit, you have only closed the inner hover function. You have not closed the outer parts, marked below:

    $(// missing closing)
     function() { // missing closing }
         $("#mewlyDiagnosed").hover(
            function() {
                $("#mewlyDiagnosed").animate({'height': '237px', 'top': "-75px"});
            }, 
            function() {
                $("#mewlyDiagnosed").animate({'height': '162px', 'top': "0px"});
            });
    
    0 讨论(0)
  • 2020-11-27 11:02

    In my case, it ended up being a simple double quote issue in my bookmarklet, remember only use single quotes on bookmarklets. Just in case this helps someone.

    0 讨论(0)
  • 2020-11-27 11:06

    I got this since I had a comment in a file I was adding to my JS, really awkward reason to what was going on - though when clicking on the VM file that's pre-rendered and catches the error, you'll find out what exactly the error was, in my case it was simply uncommenting some code I was using.

    0 讨论(0)
提交回复
热议问题