Skip to content

Instantly share code, notes, and snippets.

@HusseinMorsy
Created August 14, 2009 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HusseinMorsy/167848 to your computer and use it in GitHub Desktop.
Save HusseinMorsy/167848 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
set :views, File.dirname(__FILE__) + '/'
get '/formgen.js' do
# form kann z.B. aus Datei gelesen werden
content = '<form id="form">';
content += 'E-Mail: <input type="text" name="email" id="email"><br>';
content += 'Text: <input type="text" name="message" id="message"><br>';
content += '<input type="submit" value="send" id="send"></form>';
content += '</form>';
content += '<div id="thanks" style="display: none">';
content += '<h2>Vielen Dank</h2>';
content += '</div>'
"$(function(){
$('#dynamic').html('" + content + "');
$('#send').click(function(){
email_val = $('#email').val();
message_val = $('#message').val();
// Hier folg aufuf von /send in der die Daten übermittelt werden
$.getJSON('http://127.0.0.1:4567/send', function(data){
alert(data.status);
});
$('#form').hide();
$('#thanks').show();
return(false);
});
})";
end
get '/send' do
@email = params['email'];
@message = params['message'];
# hier wird gesendet
"{status: 'OK'}"
end
<!DOCTYPE html>
<html>
<head>
<title>Static Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
<div id="dynamic"></div>
<script type="text/javascript" src="http://127.0.0.1:4567/formgen.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment