IT

JavaScript 오류 (Uncaught SyntaxError : 예기치 않은 입력 끝)

lottoking 2020. 5. 12. 08:17
반응형

JavaScript 오류 (Uncaught SyntaxError : 예기치 않은 입력 끝)


FireFox에서는 작동하지만 Chrome 또는 IE에서는 작동하지 않는 JavaScript 코드가 있습니다.

Chrome JS 콘솔에서 다음 오류가 발생합니다.

"Uncaught SyntaxError : 예기치 않은 입력 끝".

사용중인 JavaScript 코드는 다음과 같습니다

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

오류가 마지막 줄에 있다고 말합니다. });


두 번째를 추가하십시오 });.

제대로 들여 쓰기되면 코드가 읽 힙니다.

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

당신은 결코 외부를 닫지 않았습니다 $(function() {.


필자의 경우 빈 JSON을 구문 분석하려고했습니다.

JSON.parse(stringifiedJSON);

즉, 다음과 같은 상황이 발생했습니다.

JSON.parse("");

http://jsbeautifier.org/ 는 축소 된 JS 코드를 들여 쓰는 데 도움이됩니다.

또한 Chrome 에서는 "예쁜 인쇄"를 사용할 수 있습니다. jquery.min.js내 브라우저에서 올바르게 들여 쓰기 된 Stack Overflow의 아래 스크린 샷 예를 참조하십시오. :)

여기에 이미지 설명을 입력하십시오


코드를 약간 포맷하면 내부 호버 기능 만 닫았습니다. 아래에 표시된 외부 부품을 닫지 않았습니다 ....

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

필자의 경우 Bookmarklet 에서 간단한 큰 따옴표 문제가 발생했습니다 .bookmarklet 에는 작은 따옴표 만 사용하십시오. 이것이 누군가를 돕는 경우를 대비하여.


자바 스크립트 북마크를 작성하려고 할 때이 오류가 발생했습니다. 원인을 파악할 수 없었습니다. 그러나 결국 다음 웹 사이트를 통해 북마크를 URL 인코딩하려고 시도했습니다 .http : //mrcoles.com/bookmarklet/ 그런 다음 오류가 사라 졌으므로 자바 스크립트 코드의 특정 문자가 특수 URL로 해석되는 데 문제가 있었을 것입니다 제어 문자.


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

In my case, it was caused by a missing (0) in javascript:void(0) in a anchor.


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.


I also got this error pointing to the end of the last script block on a page, only to realize the error was actually from clicking on an element with a onclick="pagename" instead of onclick="window.location='pagename'". It's not always a missing bracket!

참고 URL : https://stackoverflow.com/questions/3983088/javascript-error-uncaught-syntaxerror-unexpected-end-of-input

반응형