繁体   English   中英

Coldfusion在不刷新页面的情况下执行存储过程?

[英]Coldfusion execute a stored procedure without refreshing the page?

我有一个带有“selection”参数的存储过程

<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)
        });
    });

有没有办法做到这一点? 我知道它混合了客户端和服务器端代码,但我无法刷新页面,因为页面上有多个表单...

$(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)

            });

        });
    });

您需要在其中创建一个带有存储过程的.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() } );        
      });
    });

您需要将Stored Proc调用放入一个单独的CFM文件中,以便jquery调用。 您无法引用回到您页面上调用的那个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM