2016-11-23 3 views
1

데이터베이스에서 데이터를 채울 수있는 스크립트가 있지만 변수를 사용하려고 시도하는 변수 selected이 사용되지 않는 것 같습니다. 내 말은 Netbeans이 변수가 사용되지 않는다고 말합니다. 스크립트에 문제가 있습니까?JQuery Unused Variable Error

function get_child_options(selected) 
{ 
    if (typeof selected === 'undefined') 
    { 
     var selected = ' '; 
    } 

    var parentID = jQuery('#parent').val(); 

    jQuery.ajax(
    { 
     url: '/MyProjectName/admin/parsers/child_categories.php', 
     type: 'POST', 
     data: 
     { 
      parentID: parentID, 
      selected: selected 
     }, 
     success: function(data) 
     { 
      jQuery('#child').html(data); 
     }, 
     error: function() 
     { 
      alert("Something went wrong with the child options.") 
     }, 
    }); 
} 

jQuery('select[name="parent"]').change(get_child_options); 
+0

'var selected'는 (는) 블록 범위 밖에 있습니다. @dxcorzo가 그의 답변에서 보여지기 전에'if (typeof' – bhantol

+0

이 함수 params에 이미 정의되어 있습니다.)'var'을 제거하십시오. – Shanimal

답변

1

선택 변수를 제거합니다. 함수 매개 변수와 같은 이름의 변수가 있습니다.

function get_child_options(selected) 
{ 
    if(typeof selected === 'undefined') 
    { 
     selected = ' '; 
    } 

    var parentID = jQuery('#parent').val(); 
    jQuery.ajax(
    { 
     url: '/MyProjectName/admin/parsers/child_categories.php', 
     type: 'POST', 
     data: {'parentID': parentID, 'selected': selected}, 
     success: function(data) 
     { 
      jQuery('#child').html(data); 
     }, 
     error: function() 
     { 
      alert("Something went wrong with the child options.") 
     } 
    }); 

    jQuery('select[name="parent"]').change(get_child_options); 
} 
+0

스크립트를 시도했는데 Netbeans이 여전히 변수를 선택했습니다. '사용하지 않음'입니다. –

+0

다시 확인하십시오. –