尝试通过AJAX将表单字段值传递给CFC

时间:2016-09-16 18:59:45

标签: ajax coldfusion cfc

我有两个表单字段:

<cfinput type="text" name="ticket_id" id="ticket_id" value="#get_ticket.ticket_id#" tabindex="1" readonly="readonly" />

<textarea class='expanding' tabindex="0" name="admin_notes" id="admin_notes" cols="100" rows="5">#get_ticket.admin_notes#</textarea>

当我按下此按钮时,我试图将这些字段的值传递给CFC函数。

<input type="button" name="addTechNotes" id="addTechNotes" value="Add New Note" />

这是我的AJAX电话:

<!---Javascript for adding notes to ticket --->  
<script>
$(document).ready(function () {
      //Submit form to add record.
      $('#addTechNotes').click(function (e) 
      {          
        e.preventDefault();
        $.ajax({
        data: {tech_notes : $("#tech_notes").val(), ticket_id : $("#ticket_id").val() },
        type:'POST',
        url:'../cfcs/add_ticket_notes.cfc?method=addNotes',
        success: function() {
        $("#addNotesMessage").append( "Note successfully entered." );

        error: console.log("error");
        }
        });
    });
});
</script>

当我点击botton时,我的浏览器控制台记录:error(我的AJAX调用的错误属性)。我错过了什么?

这是我的CFC:

<cffunction name="addNotes" access="remote" returnType="string">
<cfargument name="ticket_id" type="any" required="true">
<cfargument name="tech_notes" type="any" required="yes">

<!--- localize function variables --->
<cfset var dataDetail = "">
<cfoutput>
<cfquery name="dataDetail" datasource="#datasource#">
    update closed_tickets
    set tech_notes = <cfqueryparam value="#ARGUMENTS.tech_notes#" cfsqltype="cf_sql_varchar">
    <!--- adjust cfsqltype if needed --->
    WHERE ticket_id = <cfqueryparam value="#ARGUMENTS.ticket_id#" cfsqltype="cf_sql_varchar">
</cfquery>
</cfoutput>
<cfreturn dataDetail>

2 个答案:

答案 0 :(得分:1)

您的Ajax调用有点破碎。试试这个:

RewriteRule ^(?!localhost)(.*)$ https://www.domain.com/$1 [R=301,L]

答案 1 :(得分:0)

您的textarea字段的名称和ID为&#39; admin_notes&#39;但是您引用了ID为&#39; tech_notes&#39;的元素。在ajax电话中。

我也更喜欢在数据字符串周围添加引号

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElementNS("urn:iso:std:iso:20022:tech:xsd:caie.011.011.01", "Document");
        rootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        doc.appendChild(rootElement);