jQuery未使用的可变错误



我有一个脚本来填充数据库中的数据,但是我正在尝试使用变量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);

删除您的选择变量。您有一个功能参数和一个具有相同名称的变量。

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

最新更新