Created
March 19, 2017 17:26
-
-
Save crestinglight/c8be7f1af2fdf4d6b281b2396f90742f 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
// This function gets the X and Y coordinates of where the | |
// user clicked, relative to the image. | |
function getXY(e){ | |
var xPosition = e.offsetX; | |
var yPosition = e.offsetY; | |
// Sending x and y to the server. | |
sendInfoToServer(xPosition, yPosition); | |
} | |
// Takes the x and y coordinates, passed from the getXY | |
// function, and sends them to the server to determine whether | |
// or not these coordinates are correct for Waldo. | |
function sendInfoToServer(x, y){ | |
// Making a new request. | |
var xyRequest = new XMLHttpRequest(); | |
// This line passes our x and y coordinates into a query | |
// string that Sinatra can use and determine what to do with. | |
xyRequest.open('GET', 'http://localhost:4567/puzzle01validate?xPos=' + x + '&yPos=' + y); | |
// The "onload" function executes when the server responds that | |
// it received the request. It does what it is instructed to do | |
// with those coordinates. | |
// Example: If a user clicks "like" on a facebook post, when | |
// the server responds that it received the request, it will | |
// update the number of likes on that post. | |
xyRequest.onload = saveScore; | |
//This line sends our request. | |
xyRequest.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment