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