2011-12-13 44 views
2

我有一個存儲過程具有「選擇」參數Coldfusion執行存儲過程而不刷新頁面?

<cfstoredproc procedure="MyProcedure" datasource="MyDataSource"> 
    <cfprocparam type="in" cfsqltype="cf_sql_integer" value="#selection#" null="no"> 
</cfstoredproc> 

我有一個選擇框,用戶可以選擇框,我想使用jQuery「呼」的存儲過程:

$(document).ready(function(){ 
     $('#selectbox').change(function() { 
      // update my #selection# variable 
         // run the stored procedure again (the one above) 
     }); 
    }); 

有沒有辦法做到這一點?我知道這是混合客戶端和服務器端的代碼,但是因爲有在頁面上多形式,我不能刷新頁面...

回答

6
$(document).ready(function(){ 
     $('#selectbox').change(function() { 
      $.get('pathToYourStoredProcCFM.cfm?selectVal=' + $(this).val(), function (res) { 

       // if you need to handle the response to the stored proc 
       // on the client side (which was output in your CFM code), do so here 
       // (the response from CF is stored in the "res" variable) 

      }); 

     }); 
    }); 
+0

嗯......如果我我在同一頁上改變的內容可以只是我像$獲得(「?SELECTVAL =」) – redconservatory 2011-12-14 02:12:00

0

你需要把你的存儲過程調用成一個單獨的文件CFM你的jquery打電話。你不能再引用你頁面上的那個。

2

您需要創建一個包含存儲過程的.cfm頁面,並使用AJAX調用來執行存儲的過程。

storedProc.cfm

<cfparam name="URL.selection" /> 

<cfstoredproc procedure="MyProcedure" datasource="MyDataSource"> 
    <cfprocparam type="in" cfsqltype="cf_sql_integer" value="#URL.selection#" null="no" /> 
</cfstoredproc> 

$(document).ready(function(){ 
     $('#selectbox').change(function() { 
      // update my #selection# variable 
      $.get("storedProc.cfm", { selection: $(this).val() });   
     }); 
    });