-
Notifications
You must be signed in to change notification settings - Fork 2
/
ajaxcalls.js
86 lines (84 loc) · 2.97 KB
/
ajaxcalls.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var wrongLogin = false; //wrong login flag
var loggedIn;
function loginModal() {
var modalText = wrongLogin ? 'Wrong username or password:' : 'Your username and password:';
myApp.modalLogin(modalText, function(username, password){
myApp.showIndicator();
$$.post(
'http://webratd.com/playing/ajax/check-login.php', // path to your php script
{username: username, password: password}, //pass username and password
function (response) {
myApp.hideIndicator();
if (response === 'ok') {
loggedIn = true;
// do something if correct
}
else {
wrongLogin = true; // Set wrong login flag
//loginModal(); // Call this function again
}
}
);
});
}
function mylogin(){
var oForm = document.getElementById('loginform');
var name = oForm.elements['username'].value;
var pass = oForm.elements['password'].value;
var modalText = wrongLogin ? 'Wrong username or password:' : 'Your username and password:';
$$.post(
'http://webratd.com/playing/ajax/check-login.php', // path to your php script
{username: name, password: pass}, //pass username and password
function (response) {
if (response === 'ok') {
loggedIn = true;
var a = document.createElement('a');
var linkText = document.createTextNode("Login");
a.appendChild(linkText);
a.title = "Login";
a.id = "loginlink";
a.href = "menu.html";
document.body.appendChild(a);
a.click();
// do something if correct
}
else {
loggedIn=false;
wrongLogin = true; // Set wrong login flag
alert("Wrong username or password.")
//loginModal(); // Call this function again
console.log(response);
}
}
);
return loggedIn;
}
function submitForm()
{
mylogin();
}
$$('.login-modal').on('click', function () {
if (loggedIn) {
// load something
}
else {
wrongLogin = false; //reset wrong try flag
//loginModal(); //call login modal
}
});
function sendGameResult(user,score){
$$.post(
'http://webratd.com/playing/ajax/setScore.php', // path to your php script
{username: user, score: score},
function (response) {
console.log(response);
if (response === 'ok') {
// do something if correct
console.log("Added game score");
}
else {
console.log("Failed to add score");
}
}
);
}