<?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: Bing API does callback checking for JSON-P</title>
	<atom:link href="http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 17 May 2012 07:43:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: fzammetti</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273990</link>
		<dc:creator>fzammetti</dc:creator>
		<pubDate>Wed, 17 Jun 2009 20:56:59 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273990</guid>
		<description>To &quot;bing&quot; this conversation full-circle (oh, I&#039;m so very clever- LOL): http://www.zammetti.com/blog</description>
		<content:encoded><![CDATA[<p>To &#8220;bing&#8221; this conversation full-circle (oh, I&#8217;m so very clever- LOL): <a href="http://www.zammetti.com/blog" rel="nofollow">http://www.zammetti.com/blog</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzammetti</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273974</link>
		<dc:creator>fzammetti</dc:creator>
		<pubDate>Tue, 16 Jun 2009 14:44:07 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273974</guid>
		<description>@chris: Yeah, I came to a very similar solution in my head while driving home from work last night :)  Kiss is right of course, getting at HTTP error codes doesn&#039;t seem possible, but knowing the request has timed out I think is a nice step up.</description>
		<content:encoded><![CDATA[<p>@chris: Yeah, I came to a very similar solution in my head while driving home from work last night :)  Kiss is right of course, getting at HTTP error codes doesn&#8217;t seem possible, but knowing the request has timed out I think is a nice step up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kissmyawesome</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273973</link>
		<dc:creator>kissmyawesome</dc:creator>
		<pubDate>Tue, 16 Jun 2009 14:26:04 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273973</guid>
		<description>@chris - you&#039;re right, I was just using that as a simple workaround. There&#039;s obviously no real way to do it if / until JSONRequest is implemented.</description>
		<content:encoded><![CDATA[<p>@chris &#8211; you&#8217;re right, I was just using that as a simple workaround. There&#8217;s obviously no real way to do it if / until JSONRequest is implemented.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Heilmann</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273972</link>
		<dc:creator>Chris Heilmann</dc:creator>
		<pubDate>Tue, 16 Jun 2009 14:14:21 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273972</guid>
		<description>@kissmyawesome of course you can simulate a timeout (&lt;a href=&quot;http://developer.yahoo.com/yui/get/&quot; rel=&quot;nofollow&quot;&gt;YUI get()&lt;/a&gt; is full of awesome for that) but that doesn&#039;t tell you if there was a timeout. I guess what @fzammetti wants s a proper transport of HTTP codes over JSON-P.</description>
		<content:encoded><![CDATA[<p>@kissmyawesome of course you can simulate a timeout (<a href="http://developer.yahoo.com/yui/get/" rel="nofollow">YUI get()</a> is full of awesome for that) but that doesn&#8217;t tell you if there was a timeout. I guess what @fzammetti wants s a proper transport of HTTP codes over JSON-P.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kissmyawesome</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273970</link>
		<dc:creator>kissmyawesome</dc:creator>
		<pubDate>Tue, 16 Jun 2009 10:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273970</guid>
		<description>Hmm, totally screwed the formatting. Ajaxian, for the love of god give us comment previews.</description>
		<content:encoded><![CDATA[<p>Hmm, totally screwed the formatting. Ajaxian, for the love of god give us comment previews.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kissmyawesome</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273969</link>
		<dc:creator>kissmyawesome</dc:creator>
		<pubDate>Tue, 16 Jun 2009 10:19:52 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273969</guid>
		<description>@fzammetti

What about something like this - issues the request along with a timeout that cancels the request if the callback isn&#039;t invoked after a certain period (10 secs in this example). Not tested but you get the idea:

&lt;code&gt;var requestManager={
	timeout:10,
	complete:[],
	add:function(url, callback, onError){
		var timer;
		var func=function(json){
			clearTimeout(timer);
			callback(json);
			};
		var id=this.complete.push(func)-1;
		timer=setTimeout(function(){
			requestManager.complete[id]=function(){};
			if (onError) onError();
			}, requestManager.timeout*1000);
		
		requestManager.go(url,id);
		},
	go:function(url, id){
	var src=url+&quot;&amp;callback=requestManager.complete[&quot;+id+&quot;]&quot;;
	// create / add to a script element to invoke request
	}
};

requestManager.add(&quot;http://json.com?a=b&quot;, function(json){
	// got me some JSON
	},function(){
	// timed out or otherwise failed
	});&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@fzammetti</p>
<p>What about something like this &#8211; issues the request along with a timeout that cancels the request if the callback isn&#8217;t invoked after a certain period (10 secs in this example). Not tested but you get the idea:</p>
<p><code>var requestManager={<br />
	timeout:10,<br />
	complete:[],<br />
	add:function(url, callback, onError){<br />
		var timer;<br />
		var func=function(json){<br />
			clearTimeout(timer);<br />
			callback(json);<br />
			};<br />
		var id=this.complete.push(func)-1;<br />
		timer=setTimeout(function(){<br />
			requestManager.complete[id]=function(){};<br />
			if (onError) onError();<br />
			}, requestManager.timeout*1000);</p>
<p>		requestManager.go(url,id);<br />
		},<br />
	go:function(url, id){<br />
	var src=url+"&amp;callback=requestManager.complete["+id+"]";<br />
	// create / add to a script element to invoke request<br />
	}<br />
};</p>
<p>requestManager.add("http://json.com?a=b", function(json){<br />
	// got me some JSON<br />
	},function(){<br />
	// timed out or otherwise failed<br />
	});</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kriszyp</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273964</link>
		<dc:creator>kriszyp</dc:creator>
		<pubDate>Tue, 16 Jun 2009 00:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273964</guid>
		<description>@bayareacoder: No, throwing your own error halts execution in the same way; it halts execution of the JSONP script, which doesn&#039;t affect the execution of the caller at all.</description>
		<content:encoded><![CDATA[<p>@bayareacoder: No, throwing your own error halts execution in the same way; it halts execution of the JSONP script, which doesn&#8217;t affect the execution of the caller at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bayareacoder</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273963</link>
		<dc:creator>bayareacoder</dc:creator>
		<pubDate>Mon, 15 Jun 2009 23:23:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273963</guid>
		<description>@kriszyp, The default error is not sufficient.  Throw a ReferenceError and your execution halts.  Then you may have left the page half finished and fully broken.  If the API checks that your callback is not a callable function then it can throw its own error and execution continues.

@blinkingmarquee, No need to use strict comparison with typeof.  The typeof operator always returns a string.  So something like typeof &quot;abc&quot; == &quot;string&quot; is sufficient.</description>
		<content:encoded><![CDATA[<p>@kriszyp, The default error is not sufficient.  Throw a ReferenceError and your execution halts.  Then you may have left the page half finished and fully broken.  If the API checks that your callback is not a callable function then it can throw its own error and execution continues.</p>
<p>@blinkingmarquee, No need to use strict comparison with typeof.  The typeof operator always returns a string.  So something like typeof &#8220;abc&#8221; == &#8220;string&#8221; is sufficient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blinkingmarquee</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273961</link>
		<dc:creator>blinkingmarquee</dc:creator>
		<pubDate>Mon, 15 Jun 2009 22:52:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273961</guid>
		<description>edit - Okay, they only have that in the first sample. 

to  Darkimmortal -- good rundown.</description>
		<content:encoded><![CDATA[<p>edit &#8211; Okay, they only have that in the first sample. </p>
<p>to  Darkimmortal &#8212; good rundown.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blinkingmarquee</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273960</link>
		<dc:creator>blinkingmarquee</dc:creator>
		<pubDate>Mon, 15 Jun 2009 22:50:15 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273960</guid>
		<description>Not only the not having braces for a codeblock after the if(), the typeof can always always f&#039;scking ALWAYS be checked with a === or !==</description>
		<content:encoded><![CDATA[<p>Not only the not having braces for a codeblock after the if(), the typeof can always always f&#8217;scking ALWAYS be checked with a === or !==</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzammetti</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273959</link>
		<dc:creator>fzammetti</dc:creator>
		<pubDate>Mon, 15 Jun 2009 21:21:05 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273959</guid>
		<description>I can&#039;t speak to the originality of this &quot;trick&quot;, but it&#039;s a nice little addition for JSON-P services.  I think I&#039;d prefer to wrap the callback call in try...catch and pop an alert(), and then give the caller of the JSON-P service the ability to turn this on or off (because you wouldn&#039;t want to show your users an alert() with some cryptic JS exception info in production for example, but in dev it&#039;d be very useful).

That being said, it doesn&#039;t do anything of course to address the single biggest problem with JSON-P, and that&#039;s not knowing if a response timed out or otherwise failed.  I.e., make a request that you get a 404 or 500 for and you never know it.  If someone has a clever way of dealing with that I would absolutely LOVE to hear it :)</description>
		<content:encoded><![CDATA[<p>I can&#8217;t speak to the originality of this &#8220;trick&#8221;, but it&#8217;s a nice little addition for JSON-P services.  I think I&#8217;d prefer to wrap the callback call in try&#8230;catch and pop an alert(), and then give the caller of the JSON-P service the ability to turn this on or off (because you wouldn&#8217;t want to show your users an alert() with some cryptic JS exception info in production for example, but in dev it&#8217;d be very useful).</p>
<p>That being said, it doesn&#8217;t do anything of course to address the single biggest problem with JSON-P, and that&#8217;s not knowing if a response timed out or otherwise failed.  I.e., make a request that you get a 404 or 500 for and you never know it.  If someone has a clever way of dealing with that I would absolutely LOVE to hear it :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nosredna</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273957</link>
		<dc:creator>Nosredna</dc:creator>
		<pubDate>Mon, 15 Jun 2009 18:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273957</guid>
		<description>@Darkimmortal. I also frown at that. It&#039;s an accident waiting to happen.</description>
		<content:encoded><![CDATA[<p>@Darkimmortal. I also frown at that. It&#8217;s an accident waiting to happen.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eyelidlessness</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273955</link>
		<dc:creator>eyelidlessness</dc:creator>
		<pubDate>Mon, 15 Jun 2009 18:19:40 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273955</guid>
		<description>You have an error in your sample code: &lt;code&gt;} else {(typeof console!==&#039;undefined&#039; &amp;&amp;&lt;/code&gt; should probably be &lt;code&gt;} else if(typeof console!==&#039;undefined&#039; &amp;&amp;&lt;/code&gt;

- - -

DarkImmortal,

Yes, sometimes the best programming practices means omitting some standard syntax possibilities. While leaving out the curly braces from conditionals &lt;strong&gt;works&lt;/strong&gt; it encourages coding errors. The way it&#039;s formatted in the example, it&#039;s easy to miss the if statement entirely. With other formatting, it could be easy to not see what is affected by the if statement, to accidentally change what is affected by the if statement, or to mistakenly add code that looks like it should be affected by the if statement but is not.

Use curly braces. It&#039;s only a difference of 0.002 KiB, greatly enhances readability, and could be programatically stripped for output if you really need to recover every byte possible.</description>
		<content:encoded><![CDATA[<p>You have an error in your sample code: <code>} else {(typeof console!=='undefined' &amp;&amp;</code> should probably be <code>} else if(typeof console!=='undefined' &amp;&amp;</code></p>
<p>- &#8211; -</p>
<p>DarkImmortal,</p>
<p>Yes, sometimes the best programming practices means omitting some standard syntax possibilities. While leaving out the curly braces from conditionals <strong>works</strong> it encourages coding errors. The way it&#8217;s formatted in the example, it&#8217;s easy to miss the if statement entirely. With other formatting, it could be easy to not see what is affected by the if statement, to accidentally change what is affected by the if statement, or to mistakenly add code that looks like it should be affected by the if statement but is not.</p>
<p>Use curly braces. It&#8217;s only a difference of 0.002 KiB, greatly enhances readability, and could be programatically stripped for output if you really need to recover every byte possible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darkimmortal</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273952</link>
		<dc:creator>Darkimmortal</dc:creator>
		<pubDate>Mon, 15 Jun 2009 15:34:30 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273952</guid>
		<description>&lt;blockquote&gt;and frown upon omitting the {} of the if statement&lt;/blockquote&gt;

You frown upon using standard syntax? :/</description>
		<content:encoded><![CDATA[<blockquote><p>and frown upon omitting the {} of the if statement</p></blockquote>
<p>You frown upon using standard syntax? :/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kriszyp</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273951</link>
		<dc:creator>kriszyp</dc:creator>
		<pubDate>Mon, 15 Jun 2009 13:14:49 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273951</guid>
		<description>This is a waste of bytes, the default error that is thrown when the callback is not available (ReferenceError: callback is not defined) is certainly adequate, why write a new one?</description>
		<content:encoded><![CDATA[<p>This is a waste of bytes, the default error that is thrown when the callback is not available (ReferenceError: callback is not defined) is certainly adequate, why write a new one?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jvelo</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273950</link>
		<dc:creator>jvelo</dc:creator>
		<pubDate>Mon, 15 Jun 2009 13:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273950</guid>
		<description>RESTEasy from JBoss does the same type of test as Google Maps when serving JSON-P</description>
		<content:encoded><![CDATA[<p>RESTEasy from JBoss does the same type of test as Google Maps when serving JSON-P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kissmyawesome</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273949</link>
		<dc:creator>kissmyawesome</dc:creator>
		<pubDate>Mon, 15 Jun 2009 12:57:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273949</guid>
		<description>Google maps has done this for a while, albeit without type checking:

&lt;code&gt;callback &amp;&amp; callback({...});&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Google maps has done this for a while, albeit without type checking:</p>
<p><code>callback &amp;&amp; callback({...});</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ChrisHeilmann</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273948</link>
		<dc:creator>ChrisHeilmann</dc:creator>
		<pubDate>Mon, 15 Jun 2009 12:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273948</guid>
		<description>JimmyP22 this could be another parameter.</description>
		<content:encoded><![CDATA[<p>JimmyP22 this could be another parameter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JimmyP22</title>
		<link>http://ajaxian.com/archives/bing-api-does-callback-checking-for-json-p/comment-page-1#comment-273947</link>
		<dc:creator>JimmyP22</dc:creator>
		<pubDate>Mon, 15 Jun 2009 12:26:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=6944#comment-273947</guid>
		<description>Don&#039;t bother with &quot;console&quot; - just throw a native error:

throw new Error(&#039;Callback method is undefined or a not a function&#039;);

I don&#039;t think Bing should be second-guessing API users by placing any checks before the data. Can I just have the data!??</description>
		<content:encoded><![CDATA[<p>Don&#8217;t bother with &#8220;console&#8221; &#8211; just throw a native error:</p>
<p>throw new Error(&#8216;Callback method is undefined or a not a function&#8217;);</p>
<p>I don&#8217;t think Bing should be second-guessing API users by placing any checks before the data. Can I just have the data!??</p>
]]></content:encoded>
	</item>
</channel>
</rss>

