Subversion Repositories cryptochat

Rev

Blame | Last modification | View Log | RSS feed

  1. <cfinclude template="sajax.cfm">
  2. <cfscript>
  3.         bday = "9/5/1983";
  4.         age = DateFormat(now(), "yyyy")-DateFormat(bday, "yyyy")-(DateFormat(bday, "m.dd")-DateFormat(now(), "m.dd"))/10;
  5.        
  6.         function return_struct() {
  7.                 struct = structNew();
  8.                 struct["name"] = "Anders";
  9.                 struct["age"] = age;
  10.                 return struct;
  11.         }
  12.        
  13.         function return_list() {
  14.                 list = "";
  15.                 list = listappend(list, "Anders");
  16.                 list = listappend(list, age);
  17.                 return list;
  18.         }
  19.        
  20.         function return_float() {
  21.                 return age;
  22.         }
  23.        
  24.         function return_int() {
  25.                 return int(age);
  26.         }
  27.        
  28.         function return_string() {
  29.                 return "Anders is #int(age)# years old.";
  30.         }
  31.        
  32.         sajax_request_type = "GET";
  33. //      sajax_debug_mode = true;
  34.         sajax_export("return_struct", "return_list", "return_int", "return_float", "return_string");
  35.         sajax_handle_client_request();
  36. </cfscript>
  37. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head>
  40. <title>Sajax ColdFusion return types example</title>
  41. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  42. <script type="text/javascript" src="json2.stringify.js"></script>
  43. <script type="text/javascript" src="json_stringify.js"></script>
  44. <script type="text/javascript" src="json_parse_state.js"></script>
  45. <script type="text/javascript" src="sajax.js"></script>
  46. <script type="text/javascript"><!--
  47.         <cfscript>sajax_show_javascript();</cfscript>
  48.         function display_result(val) {
  49.                 var repr;
  50.                
  51.                 repr  = "";
  52.                 repr += "Type: " + typeof val + "\n";
  53.                 repr += "Value: ";
  54.                 if (typeof val == "object" ||
  55.                         typeof val == "array") {
  56.                         repr += "{ ";
  57.                         for (var i in val)
  58.                                 repr += i + ": " + val[i] + ", ";
  59.                         repr = repr.substr(0, repr.length-2) + " }";
  60.                 } else {
  61.                         repr += val;
  62.                 }
  63.                 alert(repr);
  64.         }
  65. //-->
  66. </script>
  67. </head>
  68. <body>
  69. <button onclick="x_return_struct(display_result);">Return as struct (will become an object)</button>
  70. <button onclick="x_return_list(display_result);">Return as list (will become a string)</button>
  71. <button onclick="x_return_int(display_result);">Return as int</button>
  72. <button onclick="x_return_float(display_result);">Return as float/double</button>
  73. <button onclick="x_return_string(display_result);">Return as string</button>
  74. </body>
  75. </html>
  76.