Ok... here's the code, first up is the "dinner.cfm" page:

(Note that I moved the link to the jquery.js file to my local machine, 
and also
put .empty() after (#'contentdiv') to clear any previous response.  Also 
note that
I added <cfsetting showdebugoutput="no">.  I also set up a MySQL 5 
database for this.)



dinner.cfm 
__________________________________________________________________________

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
   
<html xmlns="http://www.w3.org/1999/xhtml";>

<cfsetting showdebugoutput="no">

<head>

    <script language="JavaScript" src="jquery.js" 
type="text/javascript"></script>
   
    <script type="text/javascript">
   
         $(document).ready(function(){
            
             $('#contentdiv').html('&nbsp;');
            
                $('#idm').change(function(){
                    var formval = {idm:$(this).val()};
               
                    $.ajax({
                                  type: "POST",
                                  url: "request_processor.cfm",
                                  dataType: "json",
                                  data: formval,
                                  success: function(response){
                                                              
$('#contentdiv').empty().fadeIn(1000).append(response.main_dish);
                                                              }
                            });       
                });           
         });
        
    </script>
   
   
    <style type="text/css">
   
          body         { font-family: Arial, Helvetica, sans-serif; }
          #databox     { border: 1px solid Gray;
                       margin:30px auto 0px auto;
                       padding: 10px;
                       width: 200px;}
        #contentdiv { color:red; font-size: 30px;  margin-top: 10px;}
       
    </style>
   
</head>

<body>

    <div align="center" id="databox">
   
        <select id="idm">
            <option value="0" SELECTED>What's for Dinner?...</option>
            <option value="1">Monday</option>
            <option value="2">Tuesday</option>
            <option value="3">Wednesday</option>
            <option value="4">Thursday</option>
            <option value="5">Friday</option>
            <option value="6">Saturday</option>
        </select>
               
        <p id="contentdiv"> </p>
       
    </div>

</body>

</html>


Here's request_processor.cfc 
____________________________________________________________________


<cfsetting showdebugoutput="no">
   
    <cfset odata = createObject("component","menudata")>
    <cfset thedata = odata.getmenuData(FORM.idm)>
    <cfset ojson = createObject("component","cfjson")>
    <cfset theresults = ojson.encode(thedata)>

    <cfoutput>#theresults#</cfoutput>


Now menudata.cfc 
_____________________________________________________________________________


<cfcomponent displayname="menudata" hint="Contains database query" 
output="false">

    <cffunction name = "getmenuData">
   
        <cfargument name = "menu_id" type="string" required="yes">
       
        <cfquery name="get_menu" datasource="menudb">
       
            select        menu.day, menu.main_dish
            from          menu
            where        menu.qsid = #arguments.menu_id#
           
        </cfquery>
       
        <cfset pstruct = structNew()>
        <cfset pstruct.day = get_menu.day>
        <cfset pstruct.main_dish = get_menu.main_dish>
       
        <cfreturn pstruct>
       
    </cffunction>

</cfcomponent>


And, then I have cfjson.cfc running, but haven't touched that code...

Rick





N K wrote:
> It didn't work even after removing the <form> tags ...
>
> If I just run the request_processor.cfm by passing a value to it using 
> cfparam it works. Not sure what going on.
>
> Can you please send me the exact code which you are running on your machine 
> for all the 3 files.
>
> Thanks 
> NK
>
>
>
>   

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316482
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to