Created
August 14, 2009 13:54
-
-
Save HusseinMorsy/167848 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
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 | |
This file contains hidden or 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
<!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