1

I was wondering if someone can tell me what is wrong with this code because it doesn't work and it does not give me any errors either.

With this code I am trying to access a component that updates a DB table each time someone press on the link.

<cfajaxproxy bind="url:http://www.example.com/admin/CRM/linktracking.cfc" />
<cfscript>
    SSLtype = (CGI.HTTPS EQ 'off')?'http://':'https://';
</cfscript>

<cfset domainname = CGI.SERVER_NAME>
<cfset domainURL = SSLtype&CGI.SERVER_NAME&CGI.SCRIPT_NAME&'?'&CGI.QUERY_STRING>

    <script>    
        function insertTracking(href) {
        var instance = new ajaxjsclass();
        instance.setCallbackHandler();
        <cfoutput>
            instance.insertTrack(href,'#surveymain.contactid#','#domainname#','#domainURL#');
        </cfoutput>
        }       
    </script> 

This is the component I am trying to access.

<cfcomponent>

<cffunction name="insertTrack" access="remote" returntype="void" >
<cfargument name="clickedURL" required="yes">
<cfargument name="contactid" required="yes">
<cfargument name="domainName" required="yes">
<cfargument name="domainURL" required="yes">

<cfquery name="q_inserttrack" datasource="dpsigweb">
update survey_tracking
set surveystarted = <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP">
where contactid= '#contactid#'
</cfquery>


<cfif ARGUMENTS.contactid NEQ ''>
    <cfscript>
        additionalInfo = '<b>Clicked URL</b> - <i>#ARGUMENTS.clickedURL#</i><br><br><b>From Site</b> - <i>#ARGUMENTS.domainURL#</i>';
        gaCFC = CreateObject("component","mod_sigweb.components.guestaccount");
        gaCFC.AddCorrespondenceCurDoctorProcedureRemote(
            functionPassword = 'password',
            contactid = '#ARGUMENTS.contactid#',
            theMessage = additionalInfo,
            statustype = 'Survey Started',
            contactresult ='Survey Started'
            );
    </cfscript>
</cfif>

</cffunction>
</cfcomponent>  

This is where I am trying to access the function from:

<a href="http://dev.example.com/surveys/survey.cfm?id=#id#&contactid=#contactid#&doctorid=#doctorid#" onClick="insertTracking(this.href)" >

I am suspecting that my <cfajaxproxy> tag may have a syntax error but when I am pressing the link I am not getting any errors.

I change my cfajaxproxy to this

<cfajaxproxy cfc="linktracking" jsclassname="ajaxjsclass"  />

but still the function does not seem to work. I even moved the component and the cfm file in the same folder but it still doesn't work.

Edit: I forgot to mention that i am sending this code in an email template. i don't know if that matters in any way. I created a test page that I am testing locally and my code works just fine. If there is something that I need to change because of that please let me know

Geo
  • 3,160
  • 6
  • 41
  • 82
  • You should implement var scoping in your function. Also use cfqueryparam on the WHERE part of your SQL. – duncan Sep 13 '12 at 13:38
  • I had the cfqueryparam but I took it off just to rule out possible bugs. I will look into var scoping thanks – Geo Sep 13 '12 at 14:10
  • 2
    Do you see the ajax call occur at all? Using FireBug in Firefox or the JavaScript console in Chrome, you should at least see if the request is made. – Adrian J. Moreno Sep 13 '12 at 15:28
  • It is giving a `ReferenceError: ajaxjsclass is not defined` and also the `var instance` is `undefined` – Geo Sep 13 '12 at 16:16

1 Answers1

0

Solution Found. I put the update query code directly on the page so when the user presses on the link and opens the page the query runs from there instead from the link.

The above code is working fine I just had issues with it because I was sending the page via email to the user. At least this is what I suspect.

Geo
  • 3,160
  • 6
  • 41
  • 82