0

データベースからデータを入力するスクリプトがありますが、変数を使用しようとしている変数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);
4

1 に答える 1

0

選択した変数を削除します。同じ名前の関数パラメーターと変数があります。

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);
}
于 2016-11-23T22:17:14.563 に答える