Web interface for collecting results and answers from students
Libraries Used:
• jQuery - v3.1.0
• pocketjs - v1.0 (by @anuvgupta)
Send an HTTP POST request to results.sfhacks.club with the following data:
- name=YourName
- answer=YourAnswer
- password=sfhacks
Bash cURL:
curl -X 'POST' -d "name=Joe&answer=a45d&password=sfhacks" http://results.sfhacks.club
jQuery AJAX:
$.ajax({
url: 'http://results.sfhacks.club',
method: 'POST',
data: {
name: 'Joe',
answer: 'a45d',
password: 'sfhacks'
},
success: function (data) {
console.log(data);
}
});
Pure JS AJAX:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200)
console.log(xhr.responseText);
};
xhr.open('POST', 'http://results.sfhacks.club', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
xhr.send('name=Joe&answer=a45d&password=sfhacks');
The admin password is an environment variable stored on results.sfhacks.club.
(Email [email protected] for access to the password)
- Deleting Database Entries
- A parameter
number
(which specifies the number ID of the entry) must be provided - A parameter
password
must be the admin password - Query Format
- number=entry_ID
- password=admin_password
- Example:
number=2&password=secret
- A parameter
- Setting the Correct Answer
- A parameter
correct
(which specifies the new correct answer) must be provided- If
correct
is set to__N/A
, then the Correct column on results.sfhacks.club is set to N/A- This feature can be used to "hide" the correct answer if there is no particular correct answer, or if it should not be shown yet
- If
- A parameter
password
must be the admin password - Query Format
- correct=new_answer
- password=admin_password
- Example:
correct=a45d&password=secret
- A parameter
- Clearing the Database
- A parameter
clear
must be provided and set totrue
- A parameter
password
must be the admin password - Query Format
- clear=true
- password=admin_password
- Example:
clear=true&password=secret
- A parameter
Four main components of the results application:
db.json
database of names/answersresults.php
pocketjs WebSocket server- uses
pocket.php
to create WebSocket server - runs indefinitely on ws://results.sfhacks.club:7998
- checks
db.json
repeatedly (every second) for changes - when changes found, pushes updated database to all open clients
- uses
index.php
HTTP server/web client- server: accepts HTTP POST requests as defined here
- updates keys in database based on posted data
- logic is defined in
api.php
- client: page seen on http://results.sfhacks.club
- displays table based on database (styled by
style.css
) - uses
app.js
to send and receive updates
- displays table based on database (styled by
- server: accepts HTTP POST requests as defined here
app.js
powers web client for the HTTP and pocketjs servers- uses jQuery AJAX to send data to
index.php
- password for sending answers is
sfhacks
- password for admin actions is a secret!
- password for sending answers is
- uses pocketjs WebSocket client
- receives changes in
db.json
fromresults.php
- receives changes in
- uses jQuery AJAX to send data to