diff options
| author | horus_arch | 2016-11-30 18:37:56 +0100 |
|---|---|---|
| committer | horus_arch | 2016-11-30 18:37:56 +0100 |
| commit | 5e8053d9ee0535f72b452cce18d581c29a435656 (patch) | |
| tree | a3857f818620169f7d566873a9f4b7aa233ddce2 /static/captcha.js | |
| parent | dbe08e91f1f931d9943b17748729aa0f03b3a003 (diff) | |
| download | iamfabulous.de-5e8053d9ee0535f72b452cce18d581c29a435656.tar.gz | |
Adds captcha to the contact form.
Diffstat (limited to 'static/captcha.js')
| -rw-r--r-- | static/captcha.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/static/captcha.js b/static/captcha.js new file mode 100644 index 0000000..6b895bb --- /dev/null +++ b/static/captcha.js @@ -0,0 +1,31 @@ +function loadJSON(path, success, error) +{ + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() + { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + if (success) + success(JSON.parse(xhr.responseText)); + } else { + if (error) + error(xhr); + } + } + }; + xhr.open("GET", path, true); + xhr.send(); +}; +loadJSON('http://127.0.0.1:3333/json/newcaptcha', + function(data){ + console.log("success", data); + var captcha = document.getElementById('captcha-img'); + captcha.src = "http://127.0.0.1:3333/captcha/" + data.captcha_id + ".png"; + var captcha_input = document.getElementById('captcha-id'); + captcha_input.value = data.captcha_id; + }, + function(data) { + console.log("error", data); + console.log(data); + } +); |
