Rev 2 | Go to most recent revision | 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!"); |
||
15 | } |
||
16 | |||
17 | let callback = function(params, vts_validation_result) { |
||
18 | $.ajax({ |
||
19 | type: "POST", |
||
20 | url: "ajax_example.php", |
||
21 | data: { |
||
22 | // This is required: |
||
23 | "vts_validation_result": vts_validation_result, |
||
24 | |||
25 | // This you can set yourself: |
||
26 | "action": "add_numbers", |
||
27 | "a": params['a'], |
||
28 | "b": params['b'] |
||
29 | }, |
||
30 | success: function(data) { |
||
4 | daniel-mar | 31 | if ("error" in data) { |
32 | $("#out").val('ERROR'); |
||
33 | alert(data["error"]); |
||
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> |