将Coldfusion表单值传递给javascript和CFC,代码不起作用

将Coldfusion表单值传递给javascript和CFC,代码不起作用,javascript,jquery,ajax,coldfusion,Javascript,Jquery,Ajax,Coldfusion,我试图将表单值传递到javascript函数中,javascript函数会将它们传递到CFC函数中,以便插入到数据库中,但它不起作用。JS代码如下: 更新:删除了警报()和url前面的“.” Coldfusion表单代码:(更新了我的表单,删除了flash类型和CFlayout) 报告名称 value=“Report Path”required=“yes”id=“reportPath”> 类别 管理工具 报告 供应商工具 公司链接 操作 报告说明 有人能告诉我,我可能做错了什么,因为

我试图将表单值传递到javascript函数中,javascript函数会将它们传递到CFC函数中,以便插入到数据库中,但它不起作用。JS代码如下:

更新:删除了警报()和url前面的“.”

Coldfusion表单代码:(更新了我的表单,删除了flash类型和CFlayout)


报告名称

value=“Report Path”required=“yes”id=“reportPath”> 类别

管理工具 报告 供应商工具 公司链接 操作 报告说明



有人能告诉我,我可能做错了什么,因为它不起作用

更新:我打开了IE控制台,脚本有一个SCRIPT1010:预期标识符错误,这行代码: **成功:函数(){

警报。(“您已成功将新报告添加到系统”)}**


更新:删除了CFFlash表单,并将HTML指定为cfform中的表单类型。AJAX调用仍然不起作用

查看您的代码,您的
cfform
上有
format=“flash”
。这将使用flash而不是HTML呈现表单。因此,jQuery无法读取表单值,因为没有HTML表单元素。如果您将其更改为
format=“html”
,那么至少您将拥有一个html表单,然后您可以开始深入研究JavaScript代码并解决这些问题


唯一需要注意的是jQuery代码。确保如果您使用
#
符号,您不在
cfoutput
块内,否则Javascript将无法按预期呈现。

我能够解决与解析cfc路径有关的问题。工作代码如下

解决方案:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script language="javascript">

    $(document).ready(function() {
        $("#createReport").click(function(f) {
            var getReportName = $("input#reportName").val();
            var getReportPath = $("input#reportPath").val();
            var getReportDesc = $("input#reportDescrip").val();
            //var getCategory   = $("input#categoryBox").val();


            $.ajax({
                type:"POST",
                url: "http://10.11.2.60/testFolder/bidirectionalreporting/codetest/components/coldfusionFunction.cfc?method=testFunc&returnformat=json",
                dataType: "JSON",
                data:{ 
                        reportName: getReportName,
                        reportPath: getReportPath,
                        reportDescrip: getReportDesc
                        //categoryBox: getCategory

                },
                success: function(result){
                    alert("You successfully added a new report to the system") } 
    });
        });
    });


</script>
<!--- CF AJAX function to create new report in DB--->
    <cffunction name="testFunc"  access="remote" description="tests the AJAX functionality and query">     <!--- Function takes in variables from CF page and AJAX call --->
    <cfargument name="mathVariable" default="8978" type="any">                                             <!--- This is just a test argument to verify ajax works before adding new fields--->
    <cfargument name="reportName" default="" type="any">                                                   <!--- This argument maps to the like named form field and is passed through AJAX call--->                
    <cfargument name="reportPath" default="" type="any">                                                   <!--- This argument maps to the like named form field and is passed through AJAX call--->
    <cfargument name="reportDescrip"  default="" type="any" >                                              <!--- This argument maps to the like named form field and is passed through AJAX call--->
    <cfargument name="categoryBox" default="Vendor Management" type="any">                                 <!--- This argument maps to the like named form field and is passed through AJAX call--->

    <cfquery name="qryTest" datasource="First_Title_Main_Dev">                                              <!--- Query creates a new report in the master report list table--->
     INSERT INTO Report_Master_List (Report_Name, URL, Report_Desc, Category)

         VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportName#">,                  <!--- report name form field references Report_Name column--->
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportPath#">,                   <!--- report path form field references ReportPath column--->
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportDescrip#">,                <!--- report descrip form field references ReportDescrip column --->
</cffunction
AJAX:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script language="javascript">

    $(document).ready(function() {
        $("#createReport").click(function(f) {
            var getReportName = $("input#reportName").val();
            var getReportPath = $("input#reportPath").val();
            var getReportDesc = $("input#reportDescrip").val();
            //var getCategory   = $("input#categoryBox").val();


            $.ajax({
                type:"POST",
                url: "http://10.11.2.60/testFolder/bidirectionalreporting/codetest/components/coldfusionFunction.cfc?method=testFunc&returnformat=json",
                dataType: "JSON",
                data:{ 
                        reportName: getReportName,
                        reportPath: getReportPath,
                        reportDescrip: getReportDesc
                        //categoryBox: getCategory

                },
                success: function(result){
                    alert("You successfully added a new report to the system") } 
    });
        });
    });


</script>
<!--- CF AJAX function to create new report in DB--->
    <cffunction name="testFunc"  access="remote" description="tests the AJAX functionality and query">     <!--- Function takes in variables from CF page and AJAX call --->
    <cfargument name="mathVariable" default="8978" type="any">                                             <!--- This is just a test argument to verify ajax works before adding new fields--->
    <cfargument name="reportName" default="" type="any">                                                   <!--- This argument maps to the like named form field and is passed through AJAX call--->                
    <cfargument name="reportPath" default="" type="any">                                                   <!--- This argument maps to the like named form field and is passed through AJAX call--->
    <cfargument name="reportDescrip"  default="" type="any" >                                              <!--- This argument maps to the like named form field and is passed through AJAX call--->
    <cfargument name="categoryBox" default="Vendor Management" type="any">                                 <!--- This argument maps to the like named form field and is passed through AJAX call--->

    <cfquery name="qryTest" datasource="First_Title_Main_Dev">                                              <!--- Query creates a new report in the master report list table--->
     INSERT INTO Report_Master_List (Report_Name, URL, Report_Desc, Category)

         VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportName#">,                  <!--- report name form field references Report_Name column--->
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportPath#">,                   <!--- report path form field references ReportPath column--->
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportDescrip#">,                <!--- report descrip form field references ReportDescrip column --->
</cffunction

$(文档).ready(函数(){
$(“#createReport”)。单击(函数(f){
var getReportName=$(“input#reportName”).val();
var getReportPath=$(“输入#报告路径”).val();
var getReportDesc=$(“输入#reportDescrip”).val();
//var getCategory=$(“输入#categoryBox”).val();
$.ajax({
类型:“POST”,
url:“http://10.11.2.60/testFolder/bidirectionalreporting/codetest/components/coldfusionFunction.cfc?method=testFunc&returnformat=json",
数据类型:“JSON”,
数据:{
reportName:getReportName,
reportPath:getReportPath,
reportDescrip:getReportDesc
//categoryBox:getCategory
},
成功:功能(结果){
警报(“您已成功将新报告添加到系统”)}
});
});
});
Coldfusion:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script language="javascript">

    $(document).ready(function() {
        $("#createReport").click(function(f) {
            var getReportName = $("input#reportName").val();
            var getReportPath = $("input#reportPath").val();
            var getReportDesc = $("input#reportDescrip").val();
            //var getCategory   = $("input#categoryBox").val();


            $.ajax({
                type:"POST",
                url: "http://10.11.2.60/testFolder/bidirectionalreporting/codetest/components/coldfusionFunction.cfc?method=testFunc&returnformat=json",
                dataType: "JSON",
                data:{ 
                        reportName: getReportName,
                        reportPath: getReportPath,
                        reportDescrip: getReportDesc
                        //categoryBox: getCategory

                },
                success: function(result){
                    alert("You successfully added a new report to the system") } 
    });
        });
    });


</script>
<!--- CF AJAX function to create new report in DB--->
    <cffunction name="testFunc"  access="remote" description="tests the AJAX functionality and query">     <!--- Function takes in variables from CF page and AJAX call --->
    <cfargument name="mathVariable" default="8978" type="any">                                             <!--- This is just a test argument to verify ajax works before adding new fields--->
    <cfargument name="reportName" default="" type="any">                                                   <!--- This argument maps to the like named form field and is passed through AJAX call--->                
    <cfargument name="reportPath" default="" type="any">                                                   <!--- This argument maps to the like named form field and is passed through AJAX call--->
    <cfargument name="reportDescrip"  default="" type="any" >                                              <!--- This argument maps to the like named form field and is passed through AJAX call--->
    <cfargument name="categoryBox" default="Vendor Management" type="any">                                 <!--- This argument maps to the like named form field and is passed through AJAX call--->

    <cfquery name="qryTest" datasource="First_Title_Main_Dev">                                              <!--- Query creates a new report in the master report list table--->
     INSERT INTO Report_Master_List (Report_Name, URL, Report_Desc, Category)

         VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportName#">,                  <!--- report name form field references Report_Name column--->
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportPath#">,                   <!--- report path form field references ReportPath column--->
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.reportDescrip#">,                <!--- report descrip form field references ReportDescrip column --->
</cffunction

插入报告主列表(报告名称、URL、报告说明、类别)
值(,
,                   
,                

你做错了的是你正在使用
cflayout
cfform
。虽然它们看起来像是一个好的解决方案,但事实并非如此。所有ColdFusion UI功能的实现都很差,使用了过时的库,并且功能非常有限。请坚持使用普通的旧HTML表单,并在布局中使用类似Bootstrap的东西。当你故意使用过时的、执行不力的工具时……你做得不对。:DAlso,你不能简单地说“它不起作用”。你需要告诉我们你预期会发生什么,实际发生了什么,以及任何错误和ColdFusion返回的内容。警报后有一个点。警报(“您已成功将新报告添加到系统”)。请删除圆点并重试。@Alex更新问题中的代码以反映您所做的更改。这可能对新访问者有所帮助。