[Solved-4 Solutions] JavaScript error (Uncaught SyntaxError: Unexpected end of input)



Error Description:

In the Chrome JS Console

"Uncaught SyntaxError: Unexpected end of input"

Solution 1:

    • When properly indented,our code reads
    $(function() {
        $("#mewlyDiagnosed").hover(function() {
            $("#mewlyDiagnosed").animate({'height': '237px', 'top': "-75px"});
        }, function() {
            $("#mewlyDiagnosed").animate({'height': '162px', 'top': "0px"});
        });
    MISSING!
    
    click below button to copy the code. By - JavaScript tutorial - team
    • We never closed the outer $(function()

    Solution 2:

      • This is what we have:
      this.authTokenStore.get()
          .then(authToken => {
              return fetch(this.serverUrl + '/REST/search?searchTerms=' + text, {
                  method: 'get',
                  headers: {
                      'Accept': 'application/json',
                      'Content-Type': 'application/json',
                      'X-Client-Auth-Token': authToken
                  }
              })
          })
          .then(this._checkStatus)
          .then(this._parseJSON)
          .then(serverGetSearchSuccess)
          .catch(serverGetSearchError);
      
      click below button to copy the code. By - JavaScript tutorial - team
      • What we don't understand and would need some help, it is with the fact that the response has a status 200, then goes to parseJSON but then goes back to checkStatus and throws that error "unexpected end of input" (debugging step by step using the chrome debugger).

      Solution 3:

        • 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);
                                 }
                             }
                   });
        
        click below button to copy the code. By - JavaScript tutorial - team

        Solution 4:

          • Also, with Google Chrome we can use "pretty print". See the example screenshot below showing jquery.min.js from Stack Overflow nicely indented right from browser
           javascript sepo

          Learn javascript - javascript tutorial - javascript sepo - javascript examples - javascript programs


          Related Searches to JavaScript error (Uncaught SyntaxError: Unexpected end of input)