What's the best way to send JavaScript array to PHP script using GET?

前端 未结 6 655
轮回少年
轮回少年 2021-01-22 13:34

I have an interactive web application powered by jQuery where users can manipulate visual objects on the screen. When done, the \"state\" of JavaScript objects should be sent to

6条回答
  •  一个人的身影
    2021-01-22 14:02

    GET or POST will probably depend on the size of your data : there is a limit on the amout of data you can pass through GET (something like 2000 bytes ; more, depending on the browser).

    There is also an other thing to take into account : if you are modifying data, you should use POST ; not GET, which is used to... get... data.

    About the format, I would really not go for anything like a custom function doing any kind of stuff like base64 : I would definitly go for JSON, which is a native Javascript notation.

    You can for instance have a look at :

    • wikipedia
    • http://www.json.org/

    There are many JS libraries that can generate JSON (probably every JS Framework can ; and there are standlone libraries like this one) ; and since PHP 5.2 there are functions in PHP to encode/decode it (see json_encode and json_decode)

提交回复
热议问题