Comments on: JSON-P output with Rails http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/ Sun, 07 Sep 2008 21:06:31 +0000 http://wordpress.org/?v=2.5 By: Ragnarok» Blog Archive » [Ruby文档中文化团队]用NetBeans Ruby 实践JMaki1.0 http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-708931 Ragnarok» Blog Archive » [Ruby文档中文化团队]用NetBeans Ruby 实践JMaki1.0 Mon, 28 Apr 2008 15:52:35 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-708931 [...] with Rails 9f/^m.PD+i:ITl.pD0 原文作者:Tim Lucas ‘`/Sn@|T0 原文地址:http://www.sitepoint.com/blogs/2 … -output-with-rails/ My0qI]0 Ruby Community:S mYM_6|1wa 译者:Ragnarok@Ruby中文社区翻译团队 [...] […] with Rails 9f/^m.PD+i:ITl.pD0 原文作者:Tim Lucas ‘`/Sn@|T0 原文地址:http://www.sitepoint.com/blogs/2 … -output-with-rails/ My0qI]0 Ruby Community:S mYM_6|1wa 译者:Ragnarok@Ruby中文社区翻译团队 […]

]]>
By: Brian http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-657017 Brian Tue, 18 Mar 2008 12:10:00 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-657017 Can you show a cross browser JSON post example? Can you show a cross browser JSON post example?

]]>
By: Michael Mahemoff http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-202140 Michael Mahemoff Tue, 13 Mar 2007 13:50:20 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-202140 Tim, yes Bob's original post is the closest thing to a definitive reference I know of. Maybe it could do with an RFC just to give it some more momentum and cred with the enterprise. Agree, "callback" works too and is arguably better as it is just as general and intuitive. Downside is it can't be inlined as an anonymous function, so it may entail a bit more JS code than some JSONP usages, which may make people want "variable" too, which starts to get complex and error-prone for API providers, which is the argument for JSONP :). If I were implementing an API, I would probably provide all three, as they can happily co-exist. Tim, yes Bob’s original post is the closest thing to a definitive reference I know of. Maybe it could do with an RFC just to give it some more momentum and cred with the enterprise.

Agree, “callback” works too and is arguably better as it is just as general and intuitive. Downside is it can’t be inlined as an anonymous function, so it may entail a bit more JS code than some JSONP usages, which may make people want “variable” too, which starts to get complex and error-prone for API providers, which is the argument for JSONP :). If I were implementing an API, I would probably provide all three, as they can happily co-exist.

]]>
By: timlucas http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-197860 timlucas Thu, 08 Mar 2007 21:25:30 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-197860 Michael: thanks for clearing that up. What's being used as the definitive document describing JSONP "protocol"? Bob Ippolito's blog post it? It's definitely sensible to reduce it all down to one parameter and keep it consistent between services. I like the idea of keeping it generic, and calling it "jsonp", though I think the concept of a "callback" parameter (as is used by a fair few APIs now) is somewhat more intuitive than a generic "jsonp" parameter. Michael: thanks for clearing that up. What’s being used as the definitive document describing JSONP “protocol”? Bob Ippolito’s blog post it? It’s definitely sensible to reduce it all down to one parameter and keep it consistent between services. I like the idea of keeping it generic, and calling it “jsonp”, though I think the concept of a “callback” parameter (as is used by a fair few APIs now) is somewhat more intuitive than a generic “jsonp” parameter.

]]>
By: Michael Mahemoff http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-197558 Michael Mahemoff Thu, 08 Mar 2007 13:14:33 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-197558 Strictly speaking, this isn't really the "JSONP" protocol AFAICT, but an application of the principle behind JSONP. That is, don't just return JSON, but instead let the caller tell the server how to augment the JSON. JSONP is a simple protocol where there's a single relevant parameter in the URL, called precisely "jsonp". The idea is to be as general as possible. Using JSONP, it is possible to specify a callback or a variable or anything else you could imagine (e.g. you could pass in "jsonp" param as "el.style.backgroundColor=" to affect an element's appearance). http://ajaxian.com/archives/jsonp-json-with-padding Strictly speaking, this isn’t really the “JSONP” protocol AFAICT, but an application of the principle behind JSONP. That is, don’t just return JSON, but instead let the caller tell the server how to augment the JSON.

JSONP is a simple protocol where there’s a single relevant parameter in the URL, called precisely “jsonp”. The idea is to be as general as possible. Using JSONP, it is possible to specify a callback or a variable or anything else you could imagine (e.g. you could pass in “jsonp” param as “el.style.backgroundColor=” to affect an element’s appearance).

http://ajaxian.com/archives/jsonp-json-with-padding

]]>
By: timlucas http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-141491 timlucas Fri, 29 Dec 2006 00:48:18 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-141491 yeah: what do you mean? There's nothing GET specific about this. It'll work just fine for PUT and POST too. yeah: what do you mean? There’s nothing GET specific about this. It’ll work just fine for PUT and POST too.

]]>
By: yeah http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-135233 yeah Sun, 24 Dec 2006 18:20:23 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-135233 so what about PUT and POST? so what about PUT and POST?

]]>
By: Oddly Zen » Blog Archive » links for 2006-12-01 http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-112587 Oddly Zen » Blog Archive » links for 2006-12-01 Fri, 01 Dec 2006 16:26:11 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-112587 [...] SitePoint Blogs » JSON-P output with Rails Wow. I like their code blocks, too. Neato. (tags: json rubyonrails rails jsonp Programming webdesign) [...] […] SitePoint Blogs » JSON-P output with Rails Wow. I like their code blocks, too. Neato. (tags: json rubyonrails rails jsonp Programming webdesign) […]

]]>
By: Dr Nic » Supporting JSON callbacks in Rails http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-104789 Dr Nic » Supporting JSON callbacks in Rails Fri, 24 Nov 2006 08:53:34 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-104789 [...] Tim Lucas wrote a great article introducing a render_json method to add to your base ApplicationController. [...] […] Tim Lucas wrote a great article introducing a render_json method to add to your base ApplicationController. […]

]]>
By: timlucas http://www.sitepoint.com/blogs/2006/10/05/json-p-output-with-rails/#comment-103520 timlucas Thu, 23 Nov 2006 06:24:03 +0000 http://www.sitepoint.com/blogs/?p=1729#comment-103520 Sorry jp, I was a little over-concise. You'll also want to respond to html: <pre><code> def show @grocery = Grocery.find(params[:id]) respond_to do |format| format.html # falls back on the rhtml file format.js { render_json @grocery.to_json } end end </code></pre> Sorry jp, I was a little over-concise. You’ll also want to respond to html:


 def show
    @grocery = Grocery.find(params[:id])
	
    respond_to do |format|
        format.html # falls back on the rhtml file
        format.js { render_json @grocery.to_json }
    end
  end
]]>