weixin_33709590 2019-04-13 17:51 采纳率: 0%
浏览 39

在php中提取json

hello,

There my ajax code

//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)},
            });
        }

I have a result like this :

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

How to extract this code in php ?

  • 写回答

1条回答 默认 最新

  • weixin_33743703 2019-04-13 17:58
    关注

    There's no need to use JSON.stringify, just pass raw array of values:

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

    On serverside you will have $_POST['product_id'] array with values.

    评论

报告相同问题?