LoginSignup
2
2

More than 5 years have passed since last update.

$.post使用時のPHP側での受け取り方(ao形式)

Last updated at Posted at 2015-02-18
sample.js
var postData = [];
$('.sample').each(function() {
    var record = {};
    record.column1 = 'aaa';
    record.column2 = 'bbb';
    record.column3 = [1,2];
    postData.push(record);
});

$.post(
    '/post/sample',
    {postData: postData},
    function(data) {
        // 何か処理
    }
);
PHP側での持ち方
array(2) {
    [0]=>
    array(3) {
        ["column1"]=>
        string(1) "aaa"
        ["column2"]=>
        string(1) "bbb"
        ["column3"]=>
        array(2) {
            [0]=>
            string(1) "1"
            [1]=>
            string(2) "2"
        }
    }
    [1]=>
    array(3) {
        ["column1"]=>
        string(1) "aaa"
        ["column2"]=>
        string(1) "bbb"
        ["column3"]=>
        array(2) {
            [0]=>
            string(1) "1"
            [1]=>
            string(2) "2"
        }
    }
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2