Jquery没有调用coldfusion cfc

edu*_*ski 5 coldfusion jquery cfc

我是jquery的新手,我正在尝试使用对话框调用和更新我的数据库.我修改了现有模板以生成下面的代码,并且无法获得jquery函数调用的函数savefee.我的javascript控制台中没有错误.任何帮助表示赞赏.

`

<cfset getfees = new artservice().getfees()>

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>

<script>
$(document).ready(function() {

    $(".artdiv").click(function() {
        var initialDiv = this;

        //based on which we click, get the current values
        var feeid = $(this).data("fee_id");
        var feetitle = $("h2", this).text();

        // set form values
        $("#fee_id").val(feeid);        
        $("#fee_title").val(feetitle);

        $("#editForm").dialog({
            buttons: {
                "Save": function() {
                    var thisDialog = $(this);
                        $.post("artservice.cfc", {
                        method: 'savefee',
                        fee_id: $("#fee_id").val(),
                        fee_title: $("#fee_title").val()
                        }, 
                    function() {
                        //update the initial div
                        $("h2", initialDiv).text($("#fee_title").val());
                        $(thisDialog).dialog("close");
                    });
                }
            }
        });
    });

});
</script>
<style>
.artdiv {
    padding: 5px;
    margin: 5px;
    background-color: #80ff80;
}
#editForm {
    display:none;   
}
</style>
</head>

<body>

<cfoutput query="getfees">

    <div class="artdiv" data-fee_id="#fee_id#">
        <h2>#fee_title#</h2>
    </div>

</cfoutput>

<div id="editForm" title="Edit Art">
    <input type="hidden" id="fee_id">
    <p>
    <b>Name:</b><br/>
    <input type="text" id="fee_title">
    </p>

</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

`

cfc如下

`

<cffunction name="getfees" access="public">
    <cfquery datasource="dsn" name="getfees" maxrows="10">select fee_id, fee_title from table</cfquery>
    <cfreturn getfees>
</cffunction>

<cffunction name="savefee" access="public">
<cfargument name="fee_id" required="yes">
<cfargument name="fee_title" required="yes">
<cfquery datasource="dsn">update table set fee_title = '#arguments.fee_title#' where fee_id = #fee_id#</cfquery>
</cffunction>
Run Code Online (Sandbox Code Playgroud)

`

application.cfc中的此函数出错"传递给onCFCRequest函数的ARGS参数不是string类型"

public void function onCFCRequest(required string cfcname, required string method, required string args) {

    return;
}
Run Code Online (Sandbox Code Playgroud)

BKK*_*BKK 5

您的功能必须设置为,access="remote"因为浏览器会直接将它们调用到CFC.


小智 4

由于“onCFCRequest”的函数定义不正确而出现错误。该函数的第三个参数是结构类型,但您已将该类型设置为字符串。所以正确的定义应该是这样的。

public void function onCFCRequest(required string cfcname, required string method, required struct args) {

    return;
}
Run Code Online (Sandbox Code Playgroud)

另外,如果您在 Application.cfc 中声明此函数,那么您需要在“onCFCRequest”中手动处理函数调用。比如您需要再次回忆一下 onCFCRequest 中的请求函数。