dqsp60748 2013-05-30 04:13
浏览 48
已采纳

将json编码的关联数组从php传递给javascript时显示错误

I have an associative array after json_encode like this

{"1":"CourseA", "2":"CourseB"}

and it is stored in a php variable named $jsonObject.Now, I want to send this to a javascript function and use that array inside that function. The function is invoked onclick like this:

 <a href="#" onclick="popup('.$jsonObject.');">link</a>

The problem is: It shows an error:invalid id popup({....

Whats the reason and what should be the solution for that? btw, I am working in moodle and the above link is shown inside a moodle block and declared inside $this->content->text.

  • 写回答

1条回答 默认 最新

  • dongtang4019 2013-05-30 04:21
    关注

    Html encode the JSON to escape special characters,

    <a href="#" onclick="popup('.htmlspecialchars($jsonObject).');">link</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现