Populating a second dropdown using ColdFusion, jQuery, and Ajax

后端 未结 2 1484
忘掉有多难
忘掉有多难 2021-01-24 16:40

I have one dropdown that has 14 values. Depending on the value chosen, it\'ll query a SQL Server database and return some clients to display in a second dropdown.

I want

2条回答
  •  粉色の甜心
    2021-01-24 17:00

    I will do my best to use the vernacular of your coding in this example

    note i am using coldfusion 9.0.1 and jquery 1.9+

    jquery/javascript
    
               $('#lstTiers').on('change', function (){        
                   $.ajax({
                   url:'Ajax-test.cfm',
                           data: {'method': 'returnSomething',
                                  'Tier': $(this).val(); },
    
                   success: function(json){
                       if (json != '' )
                    var vx='';
                       $.each (json, function(k, v){
    
                           vx+='';            
                       });
                       $('#lstClients').html(vx);
                       }
    
                   }); //end ajax()
    
           });
    

    Coldfusion

    
    
        
            
    Select * from Clients WHERE Tier = #arguments.Tier# ORDER BY 1 
        
        
    
    

    heres the thing, you need to see what return type json format is giving you, if it is coldfusion json, you would change the jquery each iteration to $.each (json.DATA, function(k, v){

    i do things in the MVC way , and like my json to be standard non CF output, so heres an example of my code

    controller

        
              
               
            
            
        select distinct d.init_contact_staff, initcap(e.pref_name_sort) name  from ben_activity_dtl d
        inner join entity e
        on e.id_number = d.init_contact_staff
    
        where d.nd_event_id =  
        
                                    and d.request_status_code =  
                                
        order by 2 asc    
            
            
        
    

    model

    
        
        
         
         
            
            
            
    
            
                
    
        
    
    

提交回复
热议问题