Skip to main content
Known Participant
June 30, 2009
Question

AJAX (jQuery) bug?

  • June 30, 2009
  • 1 reply
  • 870 views

I am trying to make an AJAX post with jQuery, and for some reason one form field is not going through.

I have a simple form where the user can post a note and check a box. If I set the form to do a normal submit (i.e. load a new page), everything works fine. If I change it to an AJAX submit, where the page doesn't reload, I get an error that says "APPLICANTID is undefined in FORM."

<form action="inc/moderation-ajax.cfm" class="moderation" id="m#extendedFetch.id#" method="post">
  <div>
    Leave <label for="note">a note for this applicant</label>:
  </div>
  <textarea id="note" name="note" title="Special Note">Hello world!</textarea>
  <div>
    <input type="checkbox" id="approve" name="approve" title="Approve This Application" value="1" checked="checked" />
    <label for="approve">Approve this application.</label>
  </div>
  <input type="hidden" id="applicantID" name="applicantID" value="#extendedFetch.id#" />
  <button type="button" class="moderate-button" value="Submit" title="Submit">Submit</button>
</form>

When you click the button, it does a jQuery AJAX call, and the ColdFusion submit code looks like this:

<cfquery name="extendedFetch" datasource="#application.dsn#">
    UPDATE My_Application
    SET note = <cfqueryparam CFSQLtype="CF_SQL_LONGVARCHAR" value="#form.note#">,
        moderation = <cfqueryparam CFSQLtype="CF_SQL_INT" value="#form.approve#">
    WHERE ID = #form.applicantID#
</cfquery>

The AJAX errors out and says: "APPLICANTID is undefined in FORM.

What is going wrong here?

    This topic has been closed for replies.

    1 reply

    Inspiring
    June 30, 2009

    Have you used the Firebug plugin for Firefox to see what is being sent to the server? 

    Verify that:

    1. A POST is being sent, not a GET request. 
    2. All form fields are included in your HTTP POST.
    3. Try changing your hidden field to a text field to see if that makes a difference.

    You might also include your Javascript code in your forum post and/or post this question to a jQuery specific forum.

    Known Participant
    June 30, 2009

    I figured out that the query string that is sent via jQuery is actually where the "form" variables are pulled from in an AJAX POST; I just had to change the variable name to match the one I was trying to display!

    (I am pretty new to jQuery and AJAX.)

    So it didn't have anything to do with ColdFusion, after all.