Skip to content

Instantly share code, notes, and snippets.

@pisi
Created May 27, 2010 11:29
Show Gist options
  • Save pisi/415706 to your computer and use it in GitHub Desktop.
Save pisi/415706 to your computer and use it in GitHub Desktop.
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
%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
(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