Created
May 27, 2010 11:29
-
-
Save pisi/415706 to your computer and use it in GitHub Desktop.
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 'rubygems' | |
require 'sinatra' | |
get '/' do | |
haml :test | |
end | |
get '/test' do | |
params[:callback] + '({ sonda: ' + params[:sonda] + '})' | |
end | |
post '/test' do | |
params[:callback] + '({ sonda: ' + params[:sonda] + '})' | |
end | |
put '/test' do | |
params[:callback] + '({ sonda: ' + params[:sonda] + '})' | |
end | |
delete '/test' do | |
params[:callback] + '({ sonda: ' + params[:sonda] + '})' | |
end | |
post '/test' do | |
params[:callback] + '({ sonda: ' + params[:sonda] + '})' | |
end |
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
%html | |
%head | |
%script{:src=> 'http://code.jquery.com/jquery-1.4.2.min.js'} | |
%script{:src=> '/test.js'} | |
%body | |
%button.GET Try GET | |
%button.POST Try POST | |
%button.PUT Try PUT | |
%button.DELETE Try DELETE |
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
(function($){ | |
$(function ready(){ | |
$('button').click(function send_by_method(){ | |
$.ajax({ | |
url: '/test', | |
type: $(this).attr('class'), | |
dataType: 'jsonp', | |
data: { | |
sonda: '123456' | |
}, | |
success: function ok(data){ | |
console.log("SUCCESS", 'sonda', data.sonda) | |
}, | |
error: function error(){ | |
console.log("ERROR") | |
} | |
}); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment