2
votes

I have to debug an Ajax Coldfusion8 application from a remote access point and am struggling to get anything to work.

The system works fine on my localhost but on the production server, I'm getting nowhere with nowhere being the page loads fine but all Ajax requests go into oblivion (commit error) without triggering a Coldfusion error.

My AJAX setup is as follows:

1). Setup

$(document).on( "click", '.su, .cu' , function() {      
     var form = $(this).closest('form'),
         switcher = form.find('input[name="form_sub"]').val(),
         service = "../serve/form_user.cfc",
         method = "process",
         returnformat = "JSON",
         targetUrl = "",
         formdata = form.serialize()+"&method="+method+"&returnformat="+returnformat,
         successHandler = function() {
              alert("hello")
              };
    ajaxFormSubmit( form, service, formdata, targetUrl, successHandler, "no" );
    return false;
    });
  1. make AJAX call

    var ajaxFormSubmit = 
        function ( form, service, formdata, targetUrl, successHandler, dataHandler ){
          $.ajax({  async: false, type: "post", 
                    url: service, data: formdata, dataType: "json",
             success: function( objResponse ){
            if (objResponse.SUCCESS){
              alert("success!");
              successHandler( objResponse )
              }
        })
    }
    
  2. Server Side
    On the server side I have a "master-slave" cfc-setup. There are type-cfcs (user, whatever), which are extensions of a main form_switch like so:

Both files are mapped from application.cfc like so:

THIS.mappings["/controllers"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "controllers";
THIS.mappings["/serve"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "services";

The type cfc extends to the form_switch

// user cfc
<cfcomponent extends="controllers.form_switch" output="false"> 
...
</cfcomponent>

The form_switch itself does all the basic stuff like validation and calling database commit in the type.cfc. Looks like this:

<cfcomponent output="false" hint="switchboard for form handling">
...
   // function called by AJAX
   <cffunction name="Process" access="remote" returntype="struct" output="false">

       <cfset var LOCAL = {} />
       <cfset LOCAL.Response = { Success = true, Errors = [], Data = "" } />

       // set form data
       <cfif IsStruct( ARGUMENTS[ 1 ] )>
           <cfset THIS.SetFormData( ARGUMENTS[ 1 ] ) />
       <cfelse>
           <cfset THIS.SetFormData( ARGUMENTS ) />
       </cfif>

       // validate
       <cfset LOCAL.Response.Errors = THIS.Validate() />

       // commit
       <cfif ArrayLen( LOCAL.Response.Errors )>
           <cfset LOCAL.Response.Success = false />
           <cfset LOCAL.Response.Errors = serializeJSON(LOCAL.Response.Errors)>
       <cfelse>
           <cftry>               
           <cfset LOCAL.Response = THIS.Commit() />
           <cfcatch>
                  <cfset LOCAL.Response.Success = false />
                  <cfset LOCAL.Response.Errors = [["server_error","commit error"]] />
           </cfcatch>
           </cftry> 
       </cfif>
      <cfreturn LOCAL.Response />
   </cffunction>
</cfcomponent>

I'm clueless why it does not work and even worse I'm guessing blind why?

The ajax returns "commit error", so I'm reaching *form_switch* alright.

Question: How can I debug this?
I tried:
Dumping to screen > does not work as I'm using AJAX.
Dumping to file (I have the full path of the server and I can access the server, so I set up a dump.txt and tried

 <cfdump output="F:\full\path\to_root\dump.txt" label="catch" var="hello"> 

but this gives me a 505 error email with

 Diagnose: An error occurred when performing a file operation write on file F:\full\path\to_root\dump.txt

I can't use the CF admin AJAX debugging because I don't have access to the CFAdmin from remote.

What else can I do? Also, if someone knows what the problem might be... answers are also welcome... Must be something basic, like messed up mappings or not having some sort of user privilige on the server ...I assume?

THANKS!

And it's Coldfusion8 and MySql 5.0.88 .... with production being MySQL 5.5, but this is another issue I think.

EDIT:
Ok. I have to use e:\ and E:\ to write to dump.txt from application.cfc. But it still does not work from form_switch.

2
permission problem? make sure you can write a file to that path. - Henry
Nope. E: vs e:... So I can dump now and know I can't seem to call any function within my CFC... searching for reasons at the moment - frequent

2 Answers

3
votes

Have you tried calling your cfc method directly in the browser using url parameters instead of the post you would do from AJAX?

Stick a cfdump in the catch with a cfabort.

Call your cfc like this: http://yourdomain.com/serve/forms users.cfc?method=process&arg1=qwe&arg2=963

This should either give you a result from your method or a dump of the error

0
votes

Basic problem indeed....

 E:\ != e:\