Copy link to clipboard
Copied
Hi I'm trying to invoke a ColdFusion function via typing in a URL in the web address bar such as:
http://domain.com/path/to/your.cfc?method=functionName&argument1=arg1Val
I have to do it this way for testing purposes. How can I invoke the following below function "showWinDOTD();" from the script below via URL? I have tried continuously the following with no luck:
http://site.com/act/actCart.cfm?method=showWinDOTD
http://site.com/act/actCart.cfm?method=showWinDOTD
Am I missing something simple?
<script>
var refreshInterval = 0;
var winFlag = false;
$(function() {
if(refreshInterval>0)
{
setTimeout('location.reload();',refreshInterval);
}
});
function submitForm() {
ColdFusion.Ajax.submitForm('DOTDform','/act/actCart.cfm',callback,errorHandler);
}
function selectDOTD(input,promoID,optionID)
{
input.disabled = true;
formObj = input.form;
formObj.PromoID.value = promoID;
formObj.OptionID.value = optionID;
ColdFusion.Ajax.submitForm(formObj.name,'/act/actCart.cfm',callback,errorHandler);
}
function callback(text)
{
text = (text.replace(/^\s+|\s+$/g,"")).toUpperCase();
if(text=='ADDED')
window.location = 'https://www.site.com/checkout/cart.cfm?uiID=16';
else if(text=='MAXED')
window.location = 'https://www.site.com/checkout/cart.cfm?uiID=43';
else if(text=='SOLD')
{
if(!winFlag)
{
winFlag = true;
showWinDOTD();
}
else
{
ColdFusion.Window.onHide('results',showWinDOTD);
ColdFusion.Window.hide('results');
}
}
else {
window.location = '/';
}
}
function errorHandler(code, msg)
{
showWinDOTD();
}
function reloadPage()
{
window.location.reload();
}
function showWinDOTD()
{
ColdFusion.Window.show('results');
ColdFusion.Window.onHide('results',reloadPage);
}
</script>
Copy link to clipboard
Copied
Hard to answer without seeing the content of your CFC (or at least then entire block defining the function you are having issues with). Have you specified access="remote" in your function definition?
-Carl V.
Copy link to clipboard
Copied
I've posted the entire block defining the function in the lower part of my post. Is that what you are looking for?
Copy link to clipboard
Copied
All you have posted is Javascript functions. There is nothing there related to a Coldfusion CFC???
Do you mean you are trying to execute a JAVASCRIPT function when the page loads?
Copy link to clipboard
Copied
Hi Haxtbh, yes, all I want to do is manually run the showWinDOTD(); function via URL, I'm guessing that that is a Javascript. How can I run it for testing? Basically, when showWinDOTD(); function runs, it gives me a pop up window. I need to test this pop up window.
Copy link to clipboard
Copied
If you just want to run the javascript when the page has loaded, call the function on the body tag onload attribute.
<body onload="showWinDOTD();">
.....
</body>
If you want to do it just when the url param is passed then just check for the param then run the function.
<body <cfif structKeyExists(url, 'method') AND url.method EQ 'showWinDOTD'>onload="showWinDOTD();"</cfif>>
....
</body>
Copy link to clipboard
Copied
Is there anyway to run this function via URL without having to edit the actual website file? That's what I'm looking for.
Copy link to clipboard
Copied
No,
Its javascript. You are trying to pass URL vars for coldfusion to do something with, but the function you want to call is not coldfusion, its javascript.
You will need to edit the page to pass the url variables. After all, it needs to know what you are trying to do.