Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php |
2 | date_default_timezone_set('Europe/Copenhagen'); |
||
3 | function test_get() { |
||
4 | return test(); |
||
5 | } |
||
6 | |||
7 | function test_post() { |
||
8 | return test(); |
||
9 | } |
||
10 | |||
11 | function test() { |
||
12 | $s = "URI: ".$_SERVER['PHP_SELF']; |
||
13 | $s .= "\n\n-- GET --\n"; |
||
14 | if(!empty($_GET["rsargs"])) |
||
15 | $s .= $_GET["rsargs"]; |
||
16 | |||
17 | $s .= "\n-- POST --\n"; |
||
18 | if(!empty($_POST["rsargs"])) |
||
19 | $s .= $_POST["rsargs"]; |
||
20 | |||
21 | return $s; |
||
22 | } |
||
23 | |||
24 | function get_the_time() { |
||
25 | return date("Y-m-d h:i:s"); |
||
26 | } |
||
27 | |||
28 | require_once("sajax.php"); |
||
29 | // $sajax_debug_mode = true; |
||
30 | $sajax_failure_redirect = "http://sajax.info/sajaxfail.html"; |
||
31 | sajax_export( |
||
32 | array("name" => "test_get", "method" => "GET"), |
||
33 | array("name" => "test_post", "method" => "POST"), |
||
34 | array("name" => "get_the_time", "method" => "GET"), |
||
35 | array("name" => "test", "method" => "GET"), |
||
36 | array("name" => "sleep", "asynchronous" => false), |
||
37 | array("name" => "otherefucntion", "uri" => "example_otheruri.php"), |
||
38 | array("name" => "otherefucntion2") |
||
39 | ); |
||
40 | sajax_handle_client_request(); |
||
41 | |||
42 | ?> |
||
43 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||
44 | <html xmlns="http://www.w3.org/1999/xhtml"> |
||
45 | <head> |
||
46 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||
47 | <title>Example of Sajax Options</title> |
||
48 | <script type="text/javascript" src="json2.stringify.js"></script> |
||
49 | <script type="text/javascript" src="json_stringify.js"></script> |
||
50 | <script type="text/javascript" src="json_parse_state.js"></script> |
||
51 | <script type="text/javascript" src="sajax.js"></script> |
||
52 | <script type="text/javascript"><!-- |
||
53 | <?php sajax_show_javascript(); ?> |
||
54 | function print_result(v) { |
||
55 | alert(v); |
||
56 | } |
||
57 | //--> |
||
58 | </script> |
||
59 | </head> |
||
60 | <body> |
||
61 | <!-- Testing if the browser supports GET --> |
||
62 | <button onclick="x_test_get(1, 2, 3, print_result);">Test GET</button> |
||
63 | |||
64 | <!-- Testing if the browser supports POST --> |
||
65 | <button onclick="x_test_post(1, 2, 3, print_result);">Test POST</button> |
||
66 | |||
67 | <!-- Forcing the function to POST --> |
||
68 | <button onclick="sajax_request_type ='POST'; x_test(1, 2, 3, print_result); sajax_request_type ='';">Test force POST</button> |
||
69 | |||
70 | <!-- if sajax_target_id is set, the sesponce will be inserted as HTML in an element with sajax_target_id for id--> |
||
71 | <button onclick="sajax_target_id = 'time'; x_get_the_time(); sajax_target_id = '';">Test updating IDs</button> |
||
72 | |||
73 | <!-- Calling a synchronous will cause the script to wait for the responce --> |
||
74 | <button onclick="x_sleep(3, function(){}); alert('Link was clicked!');">Test synchronous</button> |
||
75 | |||
76 | <!-- Different URI set at config --> |
||
77 | <button onclick="x_otherefucntion(print_result);">Call to other uri.</button> |
||
78 | |||
79 | <!-- Forece different URI at runtime --> |
||
80 | <button onclick="sajax_remote_uri = 'example_otheruri.php'; x_otherefucntion2(print_result); sajax_remote_uri = '';">Force call to other uri.</button> |
||
81 | <div id="time"><em>Time will appear here</em></div> |
||
82 | </body> |
||
83 | </html> |