-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
77 lines (60 loc) · 1.69 KB
/
index.php
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
<?php
//require_once "medoo.min.php";
//
//$db = new medoo([
// 'database_type' => 'mysql',
// 'database_name' => 'test-db',
// 'server' => 'localhost',
// 'username' => 'root',
// 'password' => 'password123',
// 'charset' => 'utf8'
//]);
//AJAX request
if ( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
{
// $db->insert('users', ['username' => uniqid()]);
usleep(350000);
echo json_encode($_POST);
return;
}
?>
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Test AJAX calls</title>
<script type="text/javascript" src="jquery-1.11.2.js"></script>
<script type="text/javascript" src="ajax-utilities.js"></script>
</head>
<body>
<a id="simpleRequest" href="#">Send simple request</a>
<a id="postRequest" href="#">Send post request</a>
<script type="text/javascript">
var a = new Ajax(),
params = {
url: 'index.php',
data: { user: 'Inevitable', password: 'a110rN0th1nG'}
};
$("a#simpleRequest").on("click", function(e){
e.preventDefault();
a.send(params)
.done(function(data){
console.log( data );
})
.always(function(){
console.log( 'SIMPLE REQUEST DONE' );
});
});
$("a#postRequest").on("click", function(e){
e.preventDefault();
a.post('index.php', { user: 'Roku', password: 'a110rN0th1nG'})
.done(function(data){
console.log( data );
})
.always(function(){
console.log( 'POST REQUEST DONE' );
});
});
</script>
</body>
</html>