【问题标题】:extract json in php在php中提取json
【发布时间】:2019-04-13 17:51:13
【问题描述】:

你好,

那里有我的 ajax 代码

//If chkArray is not empty show the <div> and create the list
        if(chkArray.length !== 0) {
            $.ajax({
                method: 'POST',
                url : 'http://localhost/shop/ext/ajax/products_compare/test.php',
//                data : JSON.stringify({product_id: chkArray})
                data: {product_id: JSON.stringify(chkArray)},
            });
        }

我有这样的结果:

array(1) {
  ["{"product_id":"]=>
  array(1) {
    [""10","9""]=>
    string(0) ""
  }
}

如何在php中提取这段代码?

【问题讨论】:

  • 不用JSON.stringify,只需data: {product_id: chkArray},

标签: php json ajax


【解决方案1】:

无需使用 JSON.stringify,只需传递原始值数组:

$.ajax({
    method: 'POST',
    url : 'http://localhost/shop/ext/ajax/products_compare/test.php',
    data: {product_id: chkArray},
});

在服务器端,您将拥有带有值的 $_POST['product_id'] 数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    相关资源
    最近更新 更多