json escape from drupal api to use in regular php environment and jquery
<p>I found this nifty plugin that lets me create dashboard widgets from external files.</p>

<p><a href="http://civicactions.com/blog/2009/feb/22/jquerydashboard_plugin#comments" rel="nofollow">http://civicactions.com/blog/2009/feb/22/jquerydashboard_plugin#comments</a></p>

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

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

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

<p>In the ajax file for this plugin is this function that I think is the culprit.</p>

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

<p>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.</p>

<p>As an example:</p>

<p>jquery 1.3.2 parses</p>

<pre><code>&lt;p&gt;Hello World&lt;/p&gt;
</code></pre>

<p>jquery 1.4+ will only parse</p>

<pre><code>Hello World (if I include the &lt;p&gt;&lt;/p&gt; then it won't load)
</code></pre>
