Advertisement
Guest User

Untitled

a guest
Jan 24th, 2011
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.36 KB | None | 0 0
  1. I've created a sample for you consisting of an index.htm and a system.cfc
  2.  
  3. Index.htm
  4.  
  5. <html>
  6.     <head>
  7.         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>     
  8.         <script>
  9.             $(document).ready(function(){  
  10.                 $(".getData").click( function(){
  11.                     var method = $(this).attr("method");
  12.                     $.getJSON( "system.cfc?method="+method,
  13.                         function(data) {
  14.                         $("#res").val( data.server_name )
  15.                     });                    
  16.                 });
  17.             });
  18.         </script>
  19.     </head>
  20.     <body>
  21.         <textarea style="height:200px;width:200px;" id="res"></textarea>
  22.         <input type="button" class="getData" method="getCgi1" value="Get Json 1" />    
  23.         <input type="button" class="getData" method="getCgi2" value="Get Json 2" />    
  24.         <input type="button" class="getData" method="getCgi3" value="Get Json 3" />    
  25.     </body>
  26. </html>
  27.  
  28. system.cfc
  29. <cfcomponent>
  30.     <cffunction name="getCgi1" access="remote" returnFormat="json" output="false">
  31.         <cfreturn cgi />
  32.     </cffunction>
  33.  
  34.     <cffunction name="getCgi2" access="remote" returnFormat="plain" output="false">
  35.         <cfreturn serializeJSON(cgi) />
  36.     </cffunction>
  37.  
  38.     <cffunction name="getCgi3" access="remote" returnFormat="plain" output="false">
  39.  
  40.         <cfset var customCgi = '{"server_name": "#cgi.server_name#","server_port": "#cgi.server_post#"}' />
  41.  
  42.         <cfreturn customCgi />
  43.     </cffunction>
  44.  
  45. </cfcomponent>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement