2 Replies Latest reply on Jul 12, 2016 9:13 AM by Steve Sommers

    returning encoded json

    coylo Level 1

      I am using the bootstrap framework for my form validation but I also am trying to trigger a success callback using Ajax and Coldfusion.

      CFMAIL gets processed OK in the mail.cfm file that I am using, however I also need the mail.cfm file to respond an encoded JSON, such as { "result": "ok" } or { "result": "error" }.

      Currently it doesn't respond anything (The current response is empty) therefore $.ajax() isn't triggering the success callback.

      Any ideas?



      // <![CDATA[


      $(document).ready(function() {



        // I am validating Bootstrap form

              framework: 'bootstrap',


              // Feedback icons

              icon: {

                  valid: 'glyphicon glyphicon-ok',

                  invalid: 'glyphicon glyphicon-remove',

                  validating: 'glyphicon glyphicon-refresh'



        // List of fields and their validation rules

              fields: {

                  name: {

                      validators: {

                          notEmpty: {

                              message: 'The name is required and cannot be empty'




                  }, // End of name



        } // End of fields



      })  // End of validating form



         .on('success.form.fv', function(e) {

              // Prevent form submission




              // Some instances you can use are

              var $form = $(e.target),        // The form instance

                  fv    = $(e.target).data('formValidation'); // FormValidation instance



              // Send all form data to back-end


                  url: 'mail.cfm',

                  type: 'POST',

                  data: $form.serialize(),

                  dataType: 'json'



        .done(function(response) {

                  // Clear the form

                  $form.formValidation('resetForm', true);



                   // Show the message

                  response.result === 'error'

                      ? $('#alertContainer')



                          .html('Sorry, cannot send the message')


                      : $('#alertContainer')



                          .html('Your message has been successfully sent')





      }); // End of script











      <cfset myStruct =

          { "result": "ok" }




          result = serializeJSON(myStruct);



        • 1. Re: returning encoded json
          BKBK Adobe Community Professional & MVP

          What about just returning the text upon success?



                      url: 'mail.cfm',

                      type: 'POST',

                      data: $form.serialize(),

                      dataType: 'json',

                      success: function(response){





          <div id="contentDiv">{ "result": "ok" }</div>

          • 2. Re: returning encoded json
            Steve Sommers Level 4

            Your mail.cfm module looks correct. What happens when you call it directly? I use something like FireBug to capture the request and then run it manually to check the results.


            I'm guessing that your mail.cfm side is correct but the javascript side has something isn't being executed the way you think it is.