Passing a js array to PHP

后端 未结 2 1975
一个人的身影
一个人的身影 2021-01-21 22:01

Why can\'t I access my array through $_POST in PHP? I\'m trying to use the jQuery $.post method. Here is the corrected code with your suggestions:

My javascript:

2条回答
  •  渐次进展
    2021-01-21 22:17

    You should serialize your array into json string:

    serializedValues = JSON.stringify(selectedValues)
    

    And pass it to php. And then decode with json_decode:

    $originalValues = json_decode($_POST['serializedValues'], 1);
    

    http://php.net/manual/ru/function.json-decode.php

提交回复
热议问题