JQuery未使用的变量错误

时间:2016-11-23 22:08:16

标签: jquery unused-variables

我有一个脚本来填充数据库中的数据但是我试图使用变量selected的变量似乎没有被使用。我的意思是Netbeans告诉我变量未被使用。脚本有问题吗?

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

1 个答案:

答案 0 :(得分: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);
}
相关问题