3 Replies Latest reply on Jul 20, 2017 2:31 AM by andrél93139241

    Loosing variables posted by Ajax Post (Coldfusion 10)

    andrél93139241 Level 1

      Hello every body. There is 7h that I search, I try examples from your forum or from other blogs or google without finding a solution to my problem.

       

      I explain

       

      I have a form which contains the result of a search. On this result, you have a "trash" icon per item where the user can delete the selected record.

      When he click on the icon, the system use a call ajax for deleting the record.

       

      code:

      jQuery('a[id^=Del_]').click(function(){

           var id = jQuery(formfield).val();

           var response = confirm("Are you sure to delete the current record ?");

           if (response){

                jQuery.ajax({

                     url: 'urlevent=MyfunctionDelete',

                     type: 'POST',

                     cache: false,

                     dataType: 'html',

                     data: {id:id},

                     success: function (data) {

                          alert('Record sucessfully deleted');

                     }

                });

           }

      }

       

      The "urlevent=MyfunctionDelete" is a call to a cfc page containing the function for deleting the record.

      When I dump the content coming from server.

       

      It is easy : EMPTY! No variables ... nothing.

       

      When I look with the tool developer and I control the detail, I see that the content of "id" is really send with the right value.

       

      the code of my function:

       

      <cffunction name="MyfunctionDelete" access="public" output="false" returntype="struct">

           <cfset var id = 0>

          

           <cfif arguments.event.isArgDefined("id")>

                <cfif isnumeric(arguments.event.getArg("id")) >

                     <cfset id = abs(arguments.event.getArg("id")) />

                </cfif>

           </cfif>

           id:<cfdump var="#id#" /><br>                <!--- response; 0 --->

           <cfdump var="#arguments.event.getargs()#" /><br>   <!--- response; empty --->

           <cfabort>

       

           <!--- .... rest of the code --->

       

      </cffunction>

       

      I don't see my mistake. There is a configuration with coldfusion server about ajax?

       

      I use jQuery version : v3.2.1, Bootstap 3.0 and Colfusion ver 10.

      Any help is welcome

       

      Thank you in advance

      Best regards

      Andre

        • 1. Re: Loosing variables posted by Ajax Post (Coldfusion 10)
          WolfShade Level 4

          Try this:

           

          <cffunction name="MyfunctionDelete" access="public" output="true" returntype="any"><!--- set returntype to 'any' and enable output --->
               <cfargument name="id" default="0" />
               <cfset arguments.id = val(arguments.id) /><!--- Ensures that if anything other than a number is submitted this will be '0'. --->
               id:<cfdump var="#arguments.id#" /><cfreturn arguments.id />
               <cfabort> 
          
               <!--- .... rest of the code --->
          
          </cffunction>
          

           

          HTH,

           

          ^ _ ^

          • 2. Re: Loosing variables posted by Ajax Post (Coldfusion 10)
            Jamo Level 2

            You should be able to also use and/or dump the FORM scope. (It's easier in many cases too.)  Doing this will let you know if it's different than what is being passed to the CFC (in case something is modifying it.)

            • 3. Re: Loosing variables posted by Ajax Post (Coldfusion 10)
              andrél93139241 Level 1

              Hello,

              I tried your example and ... without success.

              I received the error that the parameter is not passed in.

               

              So, I found the origin of the problem. The debugger of Firefox.

              Debugging.jpg

              So, If you select "Console" in the Web Developer tool (See up part of the print screen), and you execute the ajax call, when you dump the result is without your variables.

              Now, if you select "Network" and you select your "POST", Now you can see your parameter (See the lower part of the print screen).

              Now, I see my mistake in my code and I will resolve in 10min.

               

              Thank you to you for your support.

              Andre