猿问

在php中提取json

有我的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中提取此代码?


冉冉说
浏览 155回答 1
1回答

汪汪一只猫

无需使用JSON.stringify,只需传递原始值数组即可:$.ajax({&nbsp; &nbsp; method: 'POST',&nbsp; &nbsp; url : 'http://localhost/shop/ext/ajax/products_compare/test.php',&nbsp; &nbsp; data: {product_id: chkArray},});在服务器端,您将拥有$_POST['product_id']带有值的数组。
随时随地看视频慕课网APP
我要回答