Created
April 11, 2012 15:33
-
-
Save MollsReis/2360068 to your computer and use it in GitHub Desktop.
Jimson and Sinatra playing together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'jimson' | |
class Api | |
extend Jimson::Handler | |
def get_data | |
{'foo' => 'bar'} | |
end | |
end | |
get '/' do | |
haml :index | |
end | |
post '/json-rpc' do | |
Jimson::Server.new(Api.new).call(request.env) | |
end | |
__END__ | |
@@ index | |
%html | |
%head | |
%title Hobo | |
%script{ :type => 'text/javascript', :src => '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' } | |
:javascript | |
$(document).ready(function(){ | |
$('#get-data').click(function(){ | |
$.post( | |
'/json-rpc', | |
JSON.stringify({method: 'get_data', id: 1, jsonrpc: '2.0'}), | |
function(data){ $('#data').html(data.result.foo); }, | |
'json' | |
); | |
}); | |
}); | |
%body | |
%p | |
%input{ :type => 'button', :id => 'get-data', :value => 'Get Data' } | |
#data No data yet! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment