douliedai4838 2010-11-29 22:37
浏览 36
已采纳

json从drupal api中逃脱,在常规的php环境和jquery中使用

I found this nifty plugin that lets me create dashboard widgets from external files.

http://civicactions.com/blog/2009/feb/22/jquerydashboard_plugin#comments

the only problem is that its build around jquery 1.3.2 and I'm stubborn and want to use 1.4.4

The plugin still works with the latest jquery but it looses the functionality to load in the external widget content via the json call.

Well, I take that back it does load the content BUT with now a new exception. The content cannot contain <. >, & or else it will not parse correctly and not load.

In the ajax file for this plugin is this function that I think is the culprit.

// Taken from http://api.drupal.org/api/function/drupal_to_js/7 (GPL 2)
function to_js($var) {
    // json_encode() does not escape <, > and &, so we do it with str_replace()
    return str_replace(array("<", ">", "&"), array('\x3c', '\x3e', '\x26'), json_encode($var));
}

this takes in the data and passes it back, but as of 1.4.4 it won't work, I have no idea why. Is there an alternative way to do this? If i comment out this function then the widgets won't load all together regardless if it contains characters it doesn't like.

As an example:

jquery 1.3.2 parses

<p>Hello World</p>

jquery 1.4+ will only parse

Hello World (if I include the <p></p> then it won't load)
  • 写回答

2条回答 默认 最新

  • donglankui1263 2010-12-07 15:23
    关注

    You can rewrite or ask to the plugin developer to update the plugin. In order to do it yourself take a look first at Release Notes for all 1.4+ versions in order to check what was modified mainly in the ajax function. The complexity of your problem can range from very simple to very complex. You may even discover some bug that you will want to report back to jQuery.

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

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能