Skip to content

Instantly share code, notes, and snippets.

@nolman
Created March 18, 2011 20:59
Show Gist options
  • Save nolman/876825 to your computer and use it in GitHub Desktop.
Save nolman/876825 to your computer and use it in GitHub Desktop.
class ExamplesController < ApplicationController
def show
data = {:name => "Apple Pie", :price => "3.75"}
render :json => data, :callback => params[:callback]
end
end
<script type='text/javascript' src='http://www.anotherdomain.com/examples/1?callback=callback1234'></script>
<script type='text/javascript' src='http://www.anotherdomain.com/examples/1?callback=callback1234'>
callback1234({'name':'Apple Pie', 'price':'3.75'});
</script>
<html>
<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
$.getJSON("http://www.anotherdomain.com/examples/1?callback=?", function(data){
console.log(data);
});
});
</script>
</head>
<body>
JSONP
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment