<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Never worry about ASP.NET AJAX&#8217;s .d again</title>
	<atom:link href="http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/feed/" rel="self" type="application/rss+xml" />
	<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/</link>
	<description>ASP.NET and AJAX code, ideas, and examples.</description>
	<lastBuildDate>Wed, 16 May 2012 23:02:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-69703</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Tue, 15 May 2012 19:04:49 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-69703</guid>
		<description>That&#039;s easy to say now that you&#039;re &lt;em&gt;much&lt;/em&gt; more likely to be primarily targeting browsers that support native &lt;code&gt;JSON.parse&lt;/code&gt;. At the time this was written, native &lt;code&gt;JSON.parse&lt;/code&gt; was a relatively new feature. jQuery itself still used &lt;code&gt;eval()&lt;/code&gt; to deserialize &lt;em&gt;all&lt;/em&gt; JSON responses at this time, even if the browser did have native &lt;code&gt;JSON.parse&lt;/code&gt; support (in fact, &lt;a href=&quot;http://encosia.com/improving-jquery-json-performance-and-security/&quot; rel=&quot;nofollow&quot;&gt;my next post on this topic&lt;/a&gt; discussed extending this approach to use native JSON.parse when available).

For that matter, even Crockford&#039;s json2.js uses &lt;code&gt;eval()&lt;/code&gt; in its implementation of JSON.parse (after a bit of input sanitizing). There were parse-only implementations floating around, but it turned out to be prohibitively slow in the older JavaScript engines that need JSON.parse polyfilled.

I suppose what I&#039;m saying is that you have to be careful about making blanket statements about &lt;code&gt;eval()&lt;/code&gt;; especially in historical context. &quot;Eval is evil&quot; comes from Crockford, but his own acceptance of &lt;code&gt;eval()&lt;/code&gt; for JSON evaluation played a critical role in JSON being a viable format in the first place.</description>
		<content:encoded><![CDATA[<p>That&#8217;s easy to say now that you&#8217;re <em>much</em> more likely to be primarily targeting browsers that support native <code>JSON.parse</code>. At the time this was written, native <code>JSON.parse</code> was a relatively new feature. jQuery itself still used <code>eval()</code> to deserialize <em>all</em> JSON responses at this time, even if the browser did have native <code>JSON.parse</code> support (in fact, <a href="http://encosia.com/improving-jquery-json-performance-and-security/" rel="nofollow">my next post on this topic</a> discussed extending this approach to use native JSON.parse when available).</p>
<p>For that matter, even Crockford&#8217;s json2.js uses <code>eval()</code> in its implementation of JSON.parse (after a bit of input sanitizing). There were parse-only implementations floating around, but it turned out to be prohibitively slow in the older JavaScript engines that need JSON.parse polyfilled.</p>
<p>I suppose what I&#8217;m saying is that you have to be careful about making blanket statements about <code>eval()</code>; especially in historical context. &#8220;Eval is evil&#8221; comes from Crockford, but his own acceptance of <code>eval()</code> for JSON evaluation played a critical role in JSON being a viable format in the first place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Hoffman</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-68615</link>
		<dc:creator>Chris Hoffman</dc:creator>
		<pubDate>Thu, 10 May 2012 16:38:59 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-68615</guid>
		<description>Use JSON.parse instead of eval everywhere, always.  Encouraging any use of eval promotes bad programming practices.</description>
		<content:encoded><![CDATA[<p>Use JSON.parse instead of eval everywhere, always.  Encouraging any use of eval promotes bad programming practices.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-66342</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Mon, 30 Apr 2012 18:03:33 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-66342</guid>
		<description>Working with ASMX &quot;ScriptServices&quot; and ASPX page methods, there&#039;s no much choice, because you&#039;ll always be POSTing and the &lt;code&gt;.d&lt;/code&gt; is added at the framework level.

It might make sense to manually add something like this to sensitive GET-able endpoints under MVC or Web API though.</description>
		<content:encoded><![CDATA[<p>Working with ASMX &#8220;ScriptServices&#8221; and ASPX page methods, there&#8217;s no much choice, because you&#8217;ll always be POSTing and the <code>.d</code> is added at the framework level.</p>
<p>It might make sense to manually add something like this to sensitive GET-able endpoints under MVC or Web API though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Day</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-65344</link>
		<dc:creator>Jason Day</dc:creator>
		<pubDate>Thu, 26 Apr 2012 18:19:20 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-65344</guid>
		<description>I&#039;m assuming this same technique can be used with a GET and instead of the .d, a cruft such as &quot;for(;;)&quot; or &quot;while(1);&quot; ?</description>
		<content:encoded><![CDATA[<p>I&#8217;m assuming this same technique can be used with a GET and instead of the .d, a cruft such as &#8220;for(;;)&#8221; or &#8220;while(1);&#8221; ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Using jQuery in ASP.NET applications &#8211; part 1 Web Forms &#124; Bart De Meyer &#8211; Blog</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-62964</link>
		<dc:creator>Using jQuery in ASP.NET applications &#8211; part 1 Web Forms &#124; Bart De Meyer &#8211; Blog</dc:creator>
		<pubDate>Tue, 21 Feb 2012 15:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-62964</guid>
		<description>[...] return message is wrapped in a &#8220;d&#8221; variable. This is changed in the .NET 3.5 version. More info in Dave Ward&#8217;s post on Encosia. After that we create an option to be added in the listbox and append it to this [...]</description>
		<content:encoded><![CDATA[<p>[...] return message is wrapped in a &#8220;d&#8221; variable. This is changed in the .NET 3.5 version. More info in Dave Ward&#8217;s post on Encosia. After that we create an option to be added in the listbox and append it to this [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-62936</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Sun, 19 Feb 2012 19:10:21 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-62936</guid>
		<description>Just keep in mind that the extra overhead from the redundant &lt;code&gt;stringify&lt;/code&gt; and &lt;code&gt;$.parseJSON&lt;/code&gt; will become significant on larger responses, which can lead to visible stutters in your interface since JavaScript and the browser&#039;s rendering engine run together in a single thread.</description>
		<content:encoded><![CDATA[<p>Just keep in mind that the extra overhead from the redundant <code>stringify</code> and <code>$.parseJSON</code> will become significant on larger responses, which can lead to visible stutters in your interface since JavaScript and the browser&#8217;s rendering engine run together in a single thread.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Terry</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-62895</link>
		<dc:creator>Terry</dc:creator>
		<pubDate>Tue, 14 Feb 2012 17:45:36 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-62895</guid>
		<description>If all your AJAX calls are using ASP.NET 3.5, the following will work:

&lt;pre lang=&quot;javascript&quot;&gt;
    $.ajaxSetup({
        dataFilter: function (data) {
            return JSON.stringify($.parseJSON(data).d);            
        }
    });
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>If all your AJAX calls are using ASP.NET 3.5, the following will work:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    $.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        dataFilter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">parseJSON</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">d</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: nerd</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43470</link>
		<dc:creator>nerd</dc:creator>
		<pubDate>Tue, 31 May 2011 16:39:50 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43470</guid>
		<description>you right, but i think that return just a value there is a bad practice or bad use of JSON cause if we are talking about JSON (JavaScript Object Notation) responses, return a lonely value is the mistake (even if in javascript everything is an object).

You right, but if programmers do not understand what JSON it is then we should correct to teach the right way.

Regards!</description>
		<content:encoded><![CDATA[<p>you right, but i think that return just a value there is a bad practice or bad use of JSON cause if we are talking about JSON (JavaScript Object Notation) responses, return a lonely value is the mistake (even if in javascript everything is an object).</p>
<p>You right, but if programmers do not understand what JSON it is then we should correct to teach the right way.</p>
<p>Regards!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43469</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Tue, 31 May 2011 16:23:52 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43469</guid>
		<description>People often return scalar values from their methods (which is valid JSON with the .d wrapper).  A boolean indicating success/failure of an update is common, for example.  If that method returns &lt;code&gt;false&lt;/code&gt;, the ternary approach would pass &lt;br&gt;&lt;code&gt;{ d: false }&lt;/code&gt; back through the dataFilter instead of &lt;code&gt;false&lt;/code&gt;.  Same issue with any methods that might return 0 or an empty string.

If you&#039;re never returning anything but an object, the ternary should be safe, yes.</description>
		<content:encoded><![CDATA[<p>People often return scalar values from their methods (which is valid JSON with the .d wrapper).  A boolean indicating success/failure of an update is common, for example.  If that method returns <code>false</code>, the ternary approach would pass <br /><code>{ d: false }</code> back through the dataFilter instead of <code>false</code>.  Same issue with any methods that might return 0 or an empty string.</p>
<p>If you&#8217;re never returning anything but an object, the ternary should be safe, yes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nerd</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43468</link>
		<dc:creator>nerd</dc:creator>
		<pubDate>Tue, 31 May 2011 16:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43468</guid>
		<description>but if you return valid json structures there is no way that the value could be  an unexpected  &#039;false&#039; or &#039;null&#039;, actually i use this code in almost 6 applications in different servers and different .Net frameworks and i don&#039;t get any error, when you return a json object you know the sctructure and possible values, so you shouldn&#039;t get any surprise.</description>
		<content:encoded><![CDATA[<p>but if you return valid json structures there is no way that the value could be  an unexpected  &#8216;false&#8217; or &#8216;null&#8217;, actually i use this code in almost 6 applications in different servers and different .Net frameworks and i don&#8217;t get any error, when you return a json object you know the sctructure and possible values, so you shouldn&#8217;t get any surprise.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43467</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Tue, 31 May 2011 16:09:39 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43467</guid>
		<description>You would run into trouble there if the return value was intentionally the value &lt;code&gt;false&lt;/code&gt; or something ambiguously falsy like the number 0 or null.</description>
		<content:encoded><![CDATA[<p>You would run into trouble there if the return value was intentionally the value <code>false</code> or something ambiguously falsy like the number 0 or null.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nerd</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43466</link>
		<dc:creator>nerd</dc:creator>
		<pubDate>Tue, 31 May 2011 16:07:03 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43466</guid>
		<description>actually, can be converted to:

data = data.d ? data.d : data;</description>
		<content:encoded><![CDATA[<p>actually, can be converted to:</p>
<p>data = data.d ? data.d : data;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A quick guide to have jQuery call your ASP.NET PageMethods &#171; I Came, I Learned, I Blogged</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43403</link>
		<dc:creator>A quick guide to have jQuery call your ASP.NET PageMethods &#171; I Came, I Learned, I Blogged</dc:creator>
		<pubDate>Sat, 21 May 2011 15:15:58 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43403</guid>
		<description>[...] be the case, although a more complex solution for checking if a &#8216;d&#8217; is there already exists. Anyway, the proposed solution simply takes a JSON string returned from from the server, parses it [...]</description>
		<content:encoded><![CDATA[<p>[...] be the case, although a more complex solution for checking if a &#8216;d&#8217; is there already exists. Anyway, the proposed solution simply takes a JSON string returned from from the server, parses it [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ASP.NET, AJAX i JSON &#171; Asp.net &#171; Web Development &#171; Pure Development Blog</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43336</link>
		<dc:creator>ASP.NET, AJAX i JSON &#171; Asp.net &#171; Web Development &#171; Pure Development Blog</dc:creator>
		<pubDate>Sun, 08 May 2011 00:09:27 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43336</guid>
		<description>[...] Never worry about ASP.NET AJAX’s .d again [...]</description>
		<content:encoded><![CDATA[<p>[...] Never worry about ASP.NET AJAX’s .d again [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robin Herbots</title>
		<link>http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/#comment-43177</link>
		<dc:creator>Robin Herbots</dc:creator>
		<pubDate>Mon, 18 Apr 2011 11:27:29 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=883#comment-43177</guid>
		<description>As from Jquery 1.5 I use the following to solve the .d 

  converters: {
        // Evaluate text as a json expression
        &quot;text json&quot;: function(data) {
            var dataObj = $.parseJSON(data);
            return dataObj.hasOwnProperty(&#039;d&#039;) ? dataObj.d : dataObj;
        }
    }</description>
		<content:encoded><![CDATA[<p>As from Jquery 1.5 I use the following to solve the .d </p>
<p>  converters: {<br />
        // Evaluate text as a json expression<br />
        &#8220;text json&#8221;: function(data) {<br />
            var dataObj = $.parseJSON(data);<br />
            return dataObj.hasOwnProperty(&#8216;d&#8217;) ? dataObj.d : dataObj;<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

