dqrnsg6439
2016-08-23 13:26
采纳率: 100%
浏览 871

在$ .POST中传递数组/对象出错

我的javascript代码如下:

var configuration = [];

configuration["step 1"] = val1;
configuration["step 2"] = val2;
configuration["step 3"] = val3;
configuration["extraData"] = extra_data;        

var data = {
    action: 'configuration_save',
    config: configuration,
};

$.post(ajaxurl, data, function (response) {
    alert(response)
});

PHP中的$_POST['config'] 显示空白,在传递数组时我是否做错了?

PHP CODE

$current_user = wp_get_current_user();
$user_id = $current_user->ID;

add_user_meta( $user_id, "CONFIG", $_POST['config']);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhuonao8429 2016-08-23 13:40
    已采纳

    use below updated one

        var main_configuration = [] ;
        var configuration = [];
        var configuration ={
               'step 1' :  val1,
               'step 2' :  val2,
               'step 3' : val3,
               'extraData' : extra_data
        };
    
        main_configuration.push(configuration);
    
        var data = {
                action: 'configuration_save',
                config: main_configuration,
    
                };
        $.post(ajaxurl, data, function (response) {
    
                    alert(response)
    
        });
    
    点赞 打赏 评论

相关推荐 更多相似问题