Ajax关联数组

I'm confused about how associative indexing and javascript.

In my javascript, I do this:

$("input[type=button]").click(function () {
    var checked = {};
    $('input[type=checkbox]').each(function() {
        if ($(this).is(':checked')) {
            checked[$(this).attr('name')] = $(this).val();
        }
    });

    var value = [];
    value.push($(this).siblings("input[type=text]").val());

    $.ajax({ url: "scripts/php/generatehtml.php",
        data: {action: value},
        type: 'post',
        dataType: "json",
        success: ...<cut for brevity>});

So in my PHP code, I do this:

if (isset($_POST['action']) && !empty($_POST['action'])) {
    var_dump($_POST['action']);
}

And get this:

array(1) {
[0]=>
  string(5) "12277"
 }

As you can see, that's an indexed array, I want an associative array. But whenver I do something like:

value['id'] = $(this).siblings("input[type=text]").val()

Nothing gets sent.

I'm not very good wtih Ajax, and any help here would be really great!

NOTE: I did look at the other ajax array answers, but I don't think they answer my question.

If you want an associative array, initialize your variable as one. That way you can add values corresponding to specific properties like so:

var value = {};
value['id']=$(this).siblings("input[type=text]").val();

You can't use associative index arrays in JS.

You can use a JS Object instead :

var value = {};

Then you can do :

value['id'] = $(this).siblings("input[type=text]").val()

Or

value.id = $(this).siblings("input[type=text]").val()

Just a comment:

    if ($(this).is(':checked')) { 
        checked[$(this).attr('name')] = $(this).val();
    } 

can be replaced by:

    if (this.checked) {
      checked[this.name] = this.value;
    }