Created
August 7, 2012 23:45
testing basic auth ajax requests
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
#!/usr/bin/env ruby | |
# Launch, visit http://localhost:4567, authenticate with admin/secret, and wait. | |
require 'sinatra' | |
use Rack::Auth::Basic do |username, password| | |
username == 'admin' && password == 'secret' | |
end | |
get '/' do | |
'<!doctype html> | |
<meta charset="utf-8"> | |
<title>auth test</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script> | |
function getdata() { | |
console.log("getting data"); | |
$.get("/data", function(data) { | |
console.log("got data: " + data); | |
$("ul").append("<li>"+data+"</li>"); | |
}); | |
} | |
$(function () { | |
setInterval(getdata, 3000); | |
}); | |
</script> | |
<p>hello world.</p> | |
<ul> | |
</ul> | |
' | |
end | |
get '/data' do | |
rand.to_s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment