2012-06-01 3 views
0

javaScript를 사용하여 코딩을 작성했습니다. 내가 오류를 다음 표시됩니다 JsLint 확인했다 free.while 오류에 대한 Jslint를 사용하여JavaScript : 예기치 않은 데이터 오류

function showPopupSettings(userName) 
     { 
      var jsonData; 
      setLoading("Loading User Settings"); 
      jsonData = new function(){ 
        this.className = "User"; 
        this.methodName = "showPopupSettings"; 
        this.userName = userName ; 
      } 
       data = JSON.stringify(jsonData); 
       $.post('ajaxpage.php',{ submit: "commonAction",data:data }, 
            function(data) { 
             removeLoading(); 
             $("#dialog") 
              .dialog("destroy") 
              .html(data) 
              .show() 
              .dialog({ 
               modal: true, 
               title: "User Settings", 
               buttons: { 
                Cancel: function() { 
                 $(this).dialog('close'); 
                }, 

                Password: function() { 
                 showChangePasswordTable(); 
                }, 

                Save: function() { 
                 saveNewUserSettings(); 
                 $(this).dialog('close'); 
                } 
               } 
              }); 
            }); 
     } 

라인 (10) :이 오류를 해결하는 방법을 데이터

예기치 않은 ... 당신은 그 오류

답변

1

그것은 이전 라인에 의한 것

data = JSON.stringify(jsonData); 

, 세미콜론으로 끝나야하지만 그렇지 않습니다한다 :

를이 라인에
jsonData = new function(){ 
    this.className = "User"; 
    this.methodName = "showPopupSettings"; 
    this.userName = userName ; 
}; //Semi-colon here! 

코드에 다른 많은 문제가 있습니다. 위의 코드에서, 당신은 new 키워드 싶지 않은 :

jsonData = function() { //No 'new'! 
    this.className = "User"; 
    this.methodName = "showPopupSettings"; 
    this.userName = userName ; 
}; 

를 처음 선언하지 않고 data를 사용한 data = JSON.stringify(jsonData) 줄에를, 그래서 전역으로 새는. 사용하기 전에 var 문을 사용하여 data을 선언하십시오.

JSLint를 통해 코드를 실행할 때 발생하는 대부분의 오류는 공백과 관련되어 있으므로 무시할 수 있습니다.

+0

도 jsonData를 선언하고 한 번에 할당 할 수 있습니다. –

+0

@Just_Mad - 가능하지만 JSLint는 다시 불평하고 이전 선언과 결합하도록 알려줍니다. –