Created
February 25, 2016 06:46
-
-
Save Tiny-Giant/c4f4285f9f159fc816f9 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
// If we query the nodes from the DOM first, we save CPU cycles. | |
var nodes = {}; | |
nodes.row = document.getElementById("row"); | |
nodes.results = document.getElementById("results"); | |
function getStates(str) | |
{ | |
if (str.length == 0) | |
{ | |
nodes.row.innerHTML = ""; | |
nodes.results.innerHTML = ""; | |
} | |
else | |
{ | |
var xhr = new XMLHttpRequest(); | |
// The load event will fire even if the request fails. | |
xhr.addEventListener('load', function() | |
{ | |
// That way we can log the results to the console when it does fail. | |
if (xhr.status !== 200) | |
{ | |
console.log(xhr.status, xhr.statusText, xhr.responseText); | |
return; | |
} | |
nodes.results.innerHTML = xhr.responseText; | |
}, false); | |
xhr.open('GET', 'support/getStates.php?q=' + str, true); | |
xhr.send(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment