Rev 4 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4 | Rev 6 | ||
---|---|---|---|
1 | <!DOCTYPE HTML> |
1 | <!DOCTYPE HTML> |
2 | <html> |
2 | <html> |
3 | 3 | ||
4 | <head> |
4 | <head> |
5 | <title>Example of server request using Client-Challenge in order to mitigate resource starvation</title> |
5 | <title>Example of server request using Client-Challenge in order to mitigate resource starvation</title> |
6 | <meta charset="utf-8"> |
6 | <meta charset="utf-8"> |
7 | <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
7 | <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
8 | <script src="https://cdnjs.cloudflare.com/ajax/libs/js-sha3/0.8.0/sha3.min.js"></script> |
8 | <script src="https://cdnjs.cloudflare.com/ajax/libs/js-sha3/0.8.0/sha3.min.js"></script> |
9 | <script src="../ClientChallenge.js"></script> |
9 | <script src="../ClientChallenge.js"></script> |
10 | 10 | ||
11 | <script> |
11 | <script> |
12 | 12 | ||
13 | let error_cb = function (request, status, error) { |
13 | let error_cb = function (request, status, error) { |
14 | $("#out").val("Error!"); |
14 | $("#out").val("Error!"); |
- | 15 | alert(error); |
|
15 | } |
16 | } |
16 | 17 | ||
17 | let callback = function(params, vts_validation_result) { |
18 | let callback = function(params, vts_validation_result) { |
18 | $.ajax({ |
19 | $.ajax({ |
19 | type: "POST", |
20 | type: "POST", |
20 | url: "ajax_example.php", |
21 | url: "ajax_example.php", |
21 | data: { |
22 | data: { |
22 | // This is required: |
23 | // This is required: |
23 | "vts_validation_result": vts_validation_result, |
24 | "vts_validation_result": vts_validation_result, |
24 | 25 | ||
25 | // This you can set yourself: |
26 | // This you can set yourself: |
26 | "action": "add_numbers", |
27 | "action": "add_numbers", |
27 | "a": params['a'], |
28 | "a": params['a'], |
28 | "b": params['b'] |
29 | "b": params['b'] |
29 | }, |
30 | }, |
30 | success: function(data) { |
31 | success: function(data) { |
31 | if ("error" in data) { |
32 | if ("error" in data) { |
32 | $("#out").val('ERROR'); |
- | |
33 | alert(data["error"]); |
33 | error_cb(null,null,data["error"]); |
34 | } else { |
34 | } else { |
35 | $("#out").val(data["result"]); |
35 | $("#out").val(data["result"]); |
36 | } |
36 | } |
37 | }, |
37 | }, |
38 | error: error_cb |
38 | error: error_cb |
39 | }); |
39 | }); |
40 | } |
40 | } |
41 | 41 | ||
42 | function calc() { |
42 | function calc() { |
43 | var a = $("#in_a").val(); |
43 | var a = $("#in_a").val(); |
44 | var b = $("#in_b").val(); |
44 | var b = $("#in_b").val(); |
45 | var params = { |
45 | var params = { |
46 | "a": a, |
46 | "a": a, |
47 | "b": b |
47 | "b": b |
48 | }; |
48 | }; |
49 | $("#out").val("Please wait..."); |
49 | $("#out").val("Please wait..."); |
50 | vts_validated_call("ajax_get_challenge.php", callback, params, error_cb); |
50 | vts_validated_call("ajax_get_challenge.php", callback, params, error_cb); |
51 | } |
51 | } |
52 | 52 | ||
53 | </script> |
53 | </script> |
54 | </head> |
54 | </head> |
55 | 55 | ||
56 | <body> |
56 | <body> |
57 | 57 | ||
58 | <h2>Example of server request using Client-Challenge in order to mitigate resource starvation</h2> |
58 | <h2>Example of server request using Client-Challenge in order to mitigate resource starvation</h2> |
59 | 59 | ||
60 | <p><input id="in_a" value="2"> + <input id="in_b" value="3"> = <input id="out"> <input type="button" onclick="calc()" value="Calculate"></p> |
60 | <p><input id="in_a" value="2"> + <input id="in_b" value="3"> = <input id="out"> <input type="button" onclick="calc()" value="Calculate"></p> |
61 | 61 | ||
62 | </body> |
62 | </body> |
63 | 63 | ||
64 | </html> |
64 | </html> |
65 | 65 |