<?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: Simplify calling ASP.NET AJAX services from jQuery</title>
	<atom:link href="http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/</link>
	<description>ASP.NET and AJAX code, ideas, and examples.</description>
	<lastBuildDate>Thu, 11 Mar 2010 18:05:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: [Link List] jQuery, Agile, WCF REST, WF, OpenXML, Live Messenger Anniversary, Wallpapers &#124; Guru Stop</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-38032</link>
		<dc:creator>[Link List] jQuery, Agile, WCF REST, WF, OpenXML, Live Messenger Anniversary, Wallpapers &#124; Guru Stop</dc:creator>
		<pubDate>Sat, 13 Feb 2010 22:40:33 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-38032</guid>
		<description>[...] · Simplify calling ASP.NET AJAX services from jQuery [...]</description>
		<content:encoded><![CDATA[<p>[...] · Simplify calling ASP.NET AJAX services from jQuery [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Haines</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-37835</link>
		<dc:creator>Chris Haines</dc:creator>
		<pubDate>Thu, 21 Jan 2010 17:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-37835</guid>
		<description>Adam, you got it. This is a pain as it&#039;s broken my app all over! Thanks for explaining.</description>
		<content:encoded><![CDATA[<p>Adam, you got it. This is a pain as it&#8217;s broken my app all over! Thanks for explaining.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Weber</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-37801</link>
		<dc:creator>Adam Weber</dc:creator>
		<pubDate>Sun, 17 Jan 2010 17:08:35 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-37801</guid>
		<description>I think I actually answered my own question! First time for everything :)

Anyways, in my testing with jQuery 1.4, the dataFilter you outline works just fine if msg.d contains JSON. 

However, if msg.d contains a simple string value (e.g. HTML), then the dataFilter in combination with jQuery&#039;s post-filter JSON parsing will throw an exception IF the ajax dataType option is &quot;json&quot; or if you don&#039;t specify a dataType and the contentType contains &quot;json&quot;.

According to the jQuery 1.4 documentation for the &#039;dataType&#039; option: &quot;If no dataType is specified, jQuery will intelligently try to get the results, based on the MIME type of the response.&quot;

Since you need to specify a contentType (MIME type) of &#039;application/json&#039; when working against ASP.NET webservices, jQuery will attempt to parse msg.d as JSON, even if it&#039;s just a string. 

So, and maybe this is just good practice anyways, with jQuery 1.4 be sure to set the &#039;dataType&#039; option in your ajax request to &quot;html&quot; or &quot;text&quot; if msg.d is going to contain a string value. Only set the &#039;dataType&#039; option to &quot;json&quot; if msg.d is going to contain JSON (properly formatted).

Hope this makes sense and helps someone else!

P.S. Thanks for all the great posts Dave, your site is a fantastic resource!</description>
		<content:encoded><![CDATA[<p>I think I actually answered my own question! First time for everything :)</p>
<p>Anyways, in my testing with jQuery 1.4, the dataFilter you outline works just fine if msg.d contains JSON. </p>
<p>However, if msg.d contains a simple string value (e.g. HTML), then the dataFilter in combination with jQuery&#8217;s post-filter JSON parsing will throw an exception IF the ajax dataType option is &#8220;json&#8221; or if you don&#8217;t specify a dataType and the contentType contains &#8220;json&#8221;.</p>
<p>According to the jQuery 1.4 documentation for the &#8216;dataType&#8217; option: &#8220;If no dataType is specified, jQuery will intelligently try to get the results, based on the MIME type of the response.&#8221;</p>
<p>Since you need to specify a contentType (MIME type) of &#8216;application/json&#8217; when working against ASP.NET webservices, jQuery will attempt to parse msg.d as JSON, even if it&#8217;s just a string. </p>
<p>So, and maybe this is just good practice anyways, with jQuery 1.4 be sure to set the &#8216;dataType&#8217; option in your ajax request to &#8220;html&#8221; or &#8220;text&#8221; if msg.d is going to contain a string value. Only set the &#8216;dataType&#8217; option to &#8220;json&#8221; if msg.d is going to contain JSON (properly formatted).</p>
<p>Hope this makes sense and helps someone else!</p>
<p>P.S. Thanks for all the great posts Dave, your site is a fantastic resource!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Weber</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-37800</link>
		<dc:creator>Adam Weber</dc:creator>
		<pubDate>Sun, 17 Jan 2010 15:30:35 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-37800</guid>
		<description>Now that jQuery 1.4 has been released and uses JSON.parse natively, is the dataFilter no longer necessary?</description>
		<content:encoded><![CDATA[<p>Now that jQuery 1.4 has been released and uses JSON.parse natively, is the dataFilter no longer necessary?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: valse</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36804</link>
		<dc:creator>valse</dc:creator>
		<pubDate>Mon, 19 Oct 2009 16:54:05 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36804</guid>
		<description>I must edit latest jTemplate&#039;s source (0.7.8) adding on every jQuery.ajax call (if needed)

&lt;pre lang=&quot;javascript&quot;&gt;
type: &quot;GET&quot;,
contentType: &quot;application/x-www-form-urlencoded&quot;,
data: &quot;&quot;,
&lt;/pre&gt;

jquery, web services, json, jtemplate... is good and fast solution!</description>
		<content:encoded><![CDATA[<p>I must edit latest jTemplate&#8217;s source (0.7.8) adding on every jQuery.ajax call (if needed)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/x-www-form-urlencoded&quot;</span><span style="color: #339933;">,</span>
data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span></pre></div></div>

<p>jquery, web services, json, jtemplate&#8230; is good and fast solution!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36673</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Thu, 08 Oct 2009 18:57:39 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36673</guid>
		<description>$.getJSON is just a shortcut wrapper around a particular $.ajax call.  Under the hood, they all work the same way (and $.ajaxSetup affects them all).

jQuery doesn&#039;t use JSON.parse yet, but will in the next release (the change is already checked in, just pending a release).  It currently uses eval() for any JSON parsing.</description>
		<content:encoded><![CDATA[<p>$.getJSON is just a shortcut wrapper around a particular $.ajax call.  Under the hood, they all work the same way (and $.ajaxSetup affects them all).</p>
<p>jQuery doesn&#8217;t use JSON.parse yet, but will in the next release (the change is already checked in, just pending a release).  It currently uses eval() for any JSON parsing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jquery JSON Parser</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36669</link>
		<dc:creator>Jquery JSON Parser</dc:creator>
		<pubDate>Thu, 08 Oct 2009 14:48:31 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36669</guid>
		<description>I don&#039;t understand something.
When I use .getJSON doesn&#039;t it parse my json?

Should i use the eval? DOes jquery uses the JSON.parse?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand something.<br />
When I use .getJSON doesn&#8217;t it parse my json?</p>
<p>Should i use the eval? DOes jquery uses the JSON.parse?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36494</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Fri, 18 Sep 2009 01:51:38 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36494</guid>
		<description>You&#039;re right, there&#039;s no $.get() in the latest version.  Looks like that changed in 0.7.5.  

$.ajaxSetup shouldn&#039;t override that explicit GET, but the contentType still needs to be explicitly specified there in the options array.</description>
		<content:encoded><![CDATA[<p>You&#8217;re right, there&#8217;s no $.get() in the latest version.  Looks like that changed in 0.7.5.  </p>
<p>$.ajaxSetup shouldn&#8217;t override that explicit GET, but the contentType still needs to be explicitly specified there in the options array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36468</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Tue, 15 Sep 2009 14:12:58 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36468</guid>
		<description>I&#039;m not seeing where there&#039;s a $.get() call in the processTemplateURL function (version 0.7.8).  Can you be more specific in the change made to jTemplates?</description>
		<content:encoded><![CDATA[<p>I&#8217;m not seeing where there&#8217;s a $.get() call in the processTemplateURL function (version 0.7.8).  Can you be more specific in the change made to jTemplates?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asheesh Soni</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36375</link>
		<dc:creator>Asheesh Soni</dc:creator>
		<pubDate>Tue, 01 Sep 2009 07:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36375</guid>
		<description>I was having issues getting jQueryUI tabs to work in ajax mode and then I realized I had included $.ajaxSetup in my Master Page with defaults for type (POST), contentType (json), dataFilter (for .d) etc.

I changed my ajaxSetup as follows, and now UI Tabs work fine in ajax mode and thanks to Dave, I don’t have to worry about .d either :) 

&lt;pre lang=&quot;javascript&quot;&gt;$.ajaxSetup(
{
  data: &quot;{}&quot;,
  dataFilter: function(data)
  {
    var msg;
    try
    {
      if (typeof (JSON) !== &#039;undefined&#039; &amp;&amp; 
          typeof (JSON.parse) === &#039;function&#039;)
        msg = JSON.parse(data);
      else
        msg = eval(&#039;(&#039; + data + &#039;)&#039;);
    }
    catch (err)
    {
      msg = data;
    }
    if (msg.hasOwnProperty(&#039;d&#039;))
      return msg.d;
    else
      return msg;
  }
});&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I was having issues getting jQueryUI tabs to work in ajax mode and then I realized I had included $.ajaxSetup in my Master Page with defaults for type (POST), contentType (json), dataFilter (for .d) etc.</p>
<p>I changed my ajaxSetup as follows, and now UI Tabs work fine in ajax mode and thanks to Dave, I don’t have to worry about .d either :)</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>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{}&quot;</span><span style="color: #339933;">,</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: #003366; font-weight: bold;">var</span> msg<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">try</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>JSON<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">&amp;&amp;</span> 
          <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span>
        msg <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">else</span>
        msg <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> data <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      msg <span style="color: #339933;">=</span> data<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> msg.<span style="color: #660066;">d</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      <span style="color: #000066; font-weight: bold;">return</span> msg<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: Populating Table Data using jQuery &#8211; My Tech World</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36115</link>
		<dc:creator>Populating Table Data using jQuery &#8211; My Tech World</dc:creator>
		<pubDate>Mon, 10 Aug 2009 11:37:39 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36115</guid>
		<description>[...] don’t need to go into detail about this part since Dave Ward has already done it for me.  Thanks, [...]</description>
		<content:encoded><![CDATA[<p>[...] don’t need to go into detail about this part since Dave Ward has already done it for me.  Thanks, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36107</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Mon, 10 Aug 2009 01:51:39 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36107</guid>
		<description>I edited jTemplates&#039; processTemplateURL function to use an explicit $.ajax() call with the correct parameters, instead of $.get() that it uses by default.</description>
		<content:encoded><![CDATA[<p>I edited jTemplates&#8217; processTemplateURL function to use an explicit $.ajax() call with the correct parameters, instead of $.get() that it uses by default.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: francois</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36046</link>
		<dc:creator>francois</dc:creator>
		<pubDate>Wed, 05 Aug 2009 07:15:54 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36046</guid>
		<description>great article .i have a question.you said &quot;Fixing that problem wasn’t difficult, but it also wasn’t immediately obvious what had caused the issue in the first place&quot;

could you please tell us about the fix.how i can use the default settings with j templates ate the same time.</description>
		<content:encoded><![CDATA[<p>great article .i have a question.you said &#8220;Fixing that problem wasn’t difficult, but it also wasn’t immediately obvious what had caused the issue in the first place&#8221;</p>
<p>could you please tell us about the fix.how i can use the default settings with j templates ate the same time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Ward</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36038</link>
		<dc:creator>Dave Ward</dc:creator>
		<pubDate>Tue, 04 Aug 2009 16:06:27 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36038</guid>
		<description>Did you also change the URL of your $.ajax() call to use HTTPS?  Calls will fail if the protocol of the page and $.ajax URL don&#039;t match.</description>
		<content:encoded><![CDATA[<p>Did you also change the URL of your $.ajax() call to use HTTPS?  Calls will fail if the protocol of the page and $.ajax URL don&#8217;t match.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anz</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comment-36032</link>
		<dc:creator>Anz</dc:creator>
		<pubDate>Tue, 04 Aug 2009 07:15:35 +0000</pubDate>
		<guid isPermaLink="false">http://encosia.com/?p=888#comment-36032</guid>
		<description>Hi,
I am using JQuery+ Pagemethods for most of my ajax needs. Its excellent but now I have a problem with https page.. 
I have a captcha refresh script in my registration page and the refresh will happen through JQuery/Pagemethod.. Its working excellent without HTTPS but when I made my registation page SSL, the AJAX call is showing error 500 with following Response

{&quot;Message&quot;:&quot;Authentication failed.&quot;,&quot;StackTrace&quot;:null,&quot;ExceptionType&quot;:&quot;System.InvalidOperationException&quot;
}

Do you know how to solve this?

Thanks and Best Regards
Anz</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I am using JQuery+ Pagemethods for most of my ajax needs. Its excellent but now I have a problem with https page..<br />
I have a captcha refresh script in my registration page and the refresh will happen through JQuery/Pagemethod.. Its working excellent without HTTPS but when I made my registation page SSL, the AJAX call is showing error 500 with following Response</p>
<p>{&#8220;Message&#8221;:&#8221;Authentication failed.&#8221;,&#8221;StackTrace&#8221;:null,&#8221;ExceptionType&#8221;:&#8221;System.InvalidOperationException&#8221;<br />
}</p>
<p>Do you know how to solve this?</p>
<p>Thanks and Best Regards<br />
Anz</p>
]]></content:encoded>
	</item>
</channel>
</rss>
