Sending Javascript Object to PHP via Ajax

前端 未结 3 495
离开以前
离开以前 2020-12-06 00:01

I\'m learning Ajax by failure and have hit a wall:

I have an array (if it matters, the array is storing number id\'s based on what checkboxes the user checks) that i

3条回答
  •  [愿得一人]
    2020-12-06 00:20

    If your array has more then 1 dimension or is an associative array you should use JSON.

    Json turns a complete array structure into a string. This string can easily send to your php application and turned back into a php array.

    More information on json: http://www.json.org/js.html

    var my_array = { ... };
    var json = JSON.stringify( my_array );
    

    In php you can decode the string with json_decode:

    http://www.php.net/manual/en/function.json-decode.php

    var_dump(json_decode($json));
    

提交回复
热议问题