Need help using a variable as a key for $.post()

Need help using a variable as a key for $.post()

Hey Guys. I am using $.post() inside a user defined function. I am trying to pass a key value into the $key param.

I can't use  the $key variable as a key in the $.post()

Is there anyway I can use the $key var is a value for the $key.

Below is the code


  1. function add_items(element, $key){

    var cat_id = ($(element).attr("id"));

    //Insert a new row using an ajax post method, post the the cat_id to reference
    //under which category the menu item should go under
     $.post("ItemCreate.php", {key : cat_id })


     .fail(function(){
     console.log( "New Row Can't be added" );
     })

     //Append the new menu item input fields to the div class
     //.menu_item_wrapper that has an id of the mainØ category ID
     .done(function(data) {
     $('.menu_item_wrapper[id="' + cat_id + '"]').append(data);

     });

    }