summaryrefslogtreecommitdiff
path: root/static/captcha.js
blob: 7b16e7c43220315dc62f3404c5f102d77df963df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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('/json/newcaptcha',
	 function(data){
		 console.log("success", data);
		 var captcha = document.getElementById('captcha-img');
		 captcha.src = "/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);
	}
);