0
var data = [];
var id = 23;
var num = 12;
var dog_trialset = 15;
var cat_trialset = 23;

problem from here

data.push({id:{num:num, dog_trialset:dog_trialset, cat_trialset:cat_trialset}});

ajax post to php

[data] => Array
    (
        [0] => Array
            (
                [id] => Array
                    (
                        [num] => 12
                        [dog_trialset] => 15
                        [cat_trialset] => 34
                    )

            )

    )

I want [id] => Array(...) to [23] => Array(...);

Thanks

2

1 Answer 1

0

You can use a variable as the key using the subscript operator:

var row = {};
row[id] = {num:num,dog_trialset:dog_trialset,cat_trialset:cat_trialset};
data.push(row);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.