使用Ajax.Request将JSON从浏览器传递到PHP的最佳方法 [英] Best way to pass JSON from Browser to PHP using Ajax.Request

查看:57
本文介绍了使用Ajax.Request将JSON从浏览器传递到PHP的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二维数组的JSON对象,我需要使用Ajax.Request将它传递给PHP(这是我所知道的唯一方式). ...现在,我使用js函数手动序列化了数组...并以以下格式获取数据:s [] = 1& d [] = 3& [] = 4等....

Hi I have a JSON object that is a 2-dimentional array and I need to pass it to PHP using Ajax.Request (only way I know how). ...Right now I manually serialized my array using a js function...and get the data in this format: s[]=1&d[]=3&[]=4 etc. ....

我的问题是:有没有办法更直接/有效地传递JSON对象?..而不是自己序列化它?

my question is: Is there a way to pass the JSON object more directly/efficientely?..instead of serializing it myself?

感谢您的任何建议, 安德鲁

Thanks for any suggestions, Andrew

推荐答案

您还可以使用Prototype的函数 toJSON()将数组转换为JSON对象.通过Ajax调用将其传递到服务器后,只需使用PHP函数 json_decode()即可解码对象.

You can also use Prototype's function toJSON() to convert an array into a JSON object. After passing it to server via Ajax call, simply use PHP's function json_decode() to decode the object.

这篇关于使用Ajax.Request将JSON从浏览器传递到PHP的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆