-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
ajax-jquery.php
79 lines (54 loc) · 1.65 KB
/
ajax-jquery.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
78
79
<?php
declare(strict_types=1);
require __DIR__ . '/../src/tracy.php';
use Tracy\Debugger;
// For security reasons, Tracy is visible only on localhost.
// You may force Tracy to run in development mode by passing the Debugger::DEVELOPMENT instead of Debugger::DETECT.
Debugger::enable(Debugger::DETECT, __DIR__ . '/log');
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { // AJAX request
bdump('AJAX request ' . date('H:i:s'));
if (!empty($_GET['error'])) {
this_is_fatal_error();
}
$data = [rand(), rand(), rand()];
header('Content-Type: application/json');
header('Cache-Control: no-cache');
echo json_encode($data);
exit;
}
bdump('classic request ' . date('H:i:s'));
?>
<!DOCTYPE html><html class=arrow><link rel="stylesheet" href="assets/style.css">
<h1>Tracy: AJAX demo</h1>
<p>
<button>AJAX request</button> <span id=result>see Debug Bar in the bottom right corner</span>
</p>
<p>
<button class=error>Request with error</button> use ESC to toggle BlueScreen
</p>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
// default settings:
// window.TracyAutoRefresh = true;
// window.TracyMaxAjaxRows = 3;
var jqxhr;
$('button').click(function() {
$('#result').text('loading…');
if (jqxhr) {
jqxhr.abort();
}
jqxhr = $.ajax({
data: {error: $(this).hasClass('error') * 1},
dataType: 'json',
jsonp: false
}).done(function(data) {
$('#result').text('loaded: ' + data);
}).fail(function() {
$('#result').text('error');
});
});
</script>
<?php
if (Debugger::$productionMode) {
echo '<p><b>For security reasons, Tracy is visible only on localhost. Look into the source code to see how to enable Tracy.</b></p>';
}