dougai0138 2011-06-15 01:14
浏览 36
已采纳

将PHP对象传递给javascript [复制]

This question already has an answer here:

I have objects in php that each represents a "item" and all info associated with it.

And when the user browses the page, these objects should be passed to javascript. Ideally, mirroring the same structure, so I can use Raphael to display each item and its info as separate shapes on my site.

However, how do you get an object from php to javascript?

</div>
  • 写回答

4条回答 默认 最新

  • dongliyun3301 2011-06-15 01:37
    关注

    You can convert the PHP object to an array, and then use JSON function to encode it. After that, decode it from JavaScript. Here are some basic steps:

    1. Convert the PHP object to an array.

    2. Using json_encode() to encode that PHP array.

    3. Pass JSON-encoded data to PHP

    4. Decode JSON from JavaScript using JSON.parse or you can use jQuery.parseJSON to do that.

    This is an interesting tutorial about passing a JavaScript object to a PHP object. You might find it useful by watching some other featured/related videos.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面