通过ajax到php的数组

After putzing around some, I have gotten this code to work to show me an alert with the proper array of ids that are checked:

alert($("input[name=our_types]:checked").map(function () {return this.value;}).get().join(","));

I need to be able to pass it to the post action function here:

    $.post(action, {
        form_name: $('#form_name').val(),
        site_id: $('#site_id').val()


    },

I've tried doing:

   var our_types = $("input[name=our_types]:checked").map(function () {return this.value;}).get().join(",");

And then pass it like this:

    $.post(action, {
        form_name: $('#form_name').val(),
        site_id: $('#site_id').val(),
                    our_types: $('#our_types').val()

    },

But to no avail. I've been stuck on this for hours, maybe a fresh eye can help.

Heres a working code for another example:

jQuery(document).ready(function(){

    $('#contactform').submit(function(){

        var action = $(this).attr('action');

        $("#message").slideUp(750,function() {
        $('#message').hide();

        $('#submit')
            .after('<img src="assets/ajax-loader.gif" class="loader" />')
            .attr('disabled','disabled');

        $.post(action, {
            USERNAME: $('#USERNAME').val(),
            PASSWORD: $('#PASSWORD').val()
        },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown('slow');
                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled');
                if(data.match('success') != null) $('#contactform').slideUp('slow');

            }
        );

        });

        return false;

    });

});

You're very close.

When you

alert($("input[name=our_types]:checked").map(function () {return this.value;}).get().join(","));

and seeing the content is what you want.

All you need to do is assign that to a variable:

var our_types_vals = $("input[name=our_types]:checked").map(function () {return this.value;}).get().join(",");

and pass that variable into the post() function like this:

$.post(action, {
    form_name: $('#form_name').val(),
    site_id: $('#site_id').val(),
    our_types: our_types_vals
  },  // ... other codes
);

You can also bypass assigning it to a variable and pass the operation directly inside the property-value pairs object like this:

$.post(action, {
    form_name: $('#form_name').val(),
    site_id: $('#site_id').val(),
    our_types: $("input[name=our_types]:checked").map(function () {return this.value;}).get().join(",")
  },  // ... other codes
);

Please pay attention to remove the ending semi-colon on the operation to prevent syntax error inside an object literal.