• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfajax and jquery json - runs in browser but not scheduler

Explorer ,
Dec 15, 2014 Dec 15, 2014

Copy link to clipboard

Copied

This one has me quite confused.

I have a baby test routine:

testrun.cfm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<cfset dataout = timeformat(now(), "mm:ss")>

<cfquery name="testrun" datasource="#application.ccidatasource#">

    update bridge

    set testtime = <cfqueryparam cfsqltype="cf_sql_varchar" value="#dataout#">

</cfquery>

<script type="text/javascript">

$.getJSON("cciBridgeServices.cfc", {

            method: 'testThis',

            testtext: "schd",

            returnformat: 'json',

            queryformat: 'column'

        }, function(d){

            var text = "";

            var rows = d.ROWCOUNT;

        });

</script>

<body>

</body>

</html>

The service is simple as well

<cffunction name="testThis" access="remote" returntype="numeric" 
   description="Testing function used for pretty much anything" >
   <cfargument name="testtext" required="yes">
   <cflog application="yes" text="Hello auto run">
   <cfquery name="testrun" datasource="#application.ccidatasource#">
update bridge
set testcol = <cfqueryparam cfsqltype="cf_sql_varchar" value="#testtext#">
   </cfquery>
   <cfreturn 1>

    </cffunction>

If I run testrun in a browser, everything is fine.

If I create testrun as a scheduled task in the CF Administrator, or I use wget to process it, the testThis service doesn't run.

I verified this by adding the <cflog..> command.  The mm:ss gets updated, but the text does not.it?
I have tried adding a returnformat and an output="no" to the <cffunction>

Can anyone explain what is happening here and how to fix it?

Thank you in advance

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 16, 2014 Dec 16, 2014

Are the inputs required for task different all the time? You can pass variables through the task URL to the server side code or store them in a database to be read when the task executes. What you are needing to do is remove all the interactive stuff and leave just your coldfusion code.

For example, you could run the interactive process as normal but instead create a task that calls your coldfusion page with all the table updates etc rather then calling this page directly. This will then be run i

...

Votes

Translate

Translate
Explorer ,
Dec 15, 2014 Dec 15, 2014

Copy link to clipboard

Copied

BTW, it doesn't matter if I use a cf ajaxproxy or I use jquery.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

Haxtbh is right. Funnily enough, the title of your thread is itself the answer: "cfajax and jquery json - runs in browser but not scheduler".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

jQuery is something that the browser executes client side when the page is loaded. The scheduler in CF is not a browser and will not know what to do with the javascript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

Then I'm not seeing the answer.  I thought the scheduler (or wget) runs a url (a web page).  I would assume that this means there is some sort of browser emulator?  That means I can't schedule  any page to run using wget or the CF scheduler that contains javascript?

If that's the case, is there a product/solution?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

Why do you need to use javascript? The scheduler calls a URL. The idea being that its mainly got server side scripting to process, possibly with the odd output if you were debugging.

If you are using the javascript to call a CFC then why don't you use ColdFusion to do it?

You can use <cfinvoke> - https://wikidocs.adobe.com/wiki/display/coldfusionen/cfinvoke

<cfinvoke component = "cciBridgeServices.cfc" method = "testThis" returnVariable = "result">

     <cfinvokeargument  name="testtext" value="someText">

</cfinvoke>

Or something like CreateObject - CreateObject: component object - ColdFusion, English documentation - Adobe Learning Resources

<cfset comp = CreateObject('component','cciBridgeServices.cfc')>

<cfset result = comp.testThis('someText')>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

I replied "to original discussion"  I don't know if you get notified that way, so I'm just "poking" you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

EdGioja wrote:

Then I'm not seeing the answer.  I thought the scheduler (or wget) runs a url (a web page).

The scheduler does run the URL, but ColdFusion has no browser capability for running Javascript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

I appreciate that question haxtbh.  The answer may lie in a basic misunderstanding on my part that I need to be educated on (so please be kind).  Keep in mind that this is a very small and targeted sample of a much larger application...the sample program is only designed to point out the problem.

In the bigger application, I have a button. The user sets some data on the form and when the user clicks the button, it's onclick method calls a javascript function.  That javascript function is a controller that runs a number of other subroutines.  These subroutines, among  other things, needs to update tables.  The way I've done that interactively is to use either cfajaxproxy or jquery to run a service that is actually CF code called by the javascript function.

All of this works fine interactively   My task now is to take this interactive process, add some default inputs to the form, and run it periodically via a scheduler.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

Are the inputs required for task different all the time? You can pass variables through the task URL to the server side code or store them in a database to be read when the task executes. What you are needing to do is remove all the interactive stuff and leave just your coldfusion code.

For example, you could run the interactive process as normal but instead create a task that calls your coldfusion page with all the table updates etc rather then calling this page directly. This will then be run initially for the first time and then scheduled for a future time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

I've actually reached the same conclusion at about the same time.  My issue (and my educational take-away) is that I wrote it based on an input/status screen that calls functions starting with a javascript function attached to the "start" button.  .  Since all of those functions are self contained and can be invoked, and all of the inputs are known (or can be read from a table), I can remove the U/I and replace it with a controller that does the invokes using straight CF code.

The other issue I will have to address when I'm looking at my code is to ensure I don't have any SESSION variables.

My basic misunderstanding was that scheduler was server-side only.  I was thinking that it emulated a browser.

I thank you for your help and patience.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2014 Dec 16, 2014

Copy link to clipboard

Copied

LATEST

Just in case someone else stumbles across this and finds it helpful...

It might also be helpful to know that you don't have SESSION variables BUT, if the CLIENT variables are stored in a database rather than cookies (an CF is set up to allow them), you do have access to THOSE.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation