Copy link to clipboard
Copied
I have situation that requires an action to happen in an external URL without displaying a page. The page at the URL is not necessarily a ColdFusion template.
Specifically, I have an AddToCart URL; I would like to place an item in the shopping cart, but have no display of the page at that URL when the item is added to the cart. This way, a shopper can create a cart without having a page show up each time an item is added, then later go look at the completed cart.
Can this be accomplished with CF? If so, how?
I did some googling and looked through these forums but could not find anything – and I really have no idea what keywords to use for a search like this.
I would appreciate any ideas.
Regards to all,
Carlos
Copy link to clipboard
Copied
There are several ways you could do something like this.
Whcih ones you choose would start with how you plan to get the data from the client to the server.
If you want to do basic form submits, then the action page has to do something to either display the resluts OR to redirect the client to a page that displays the results. Even if the result is just the same page the user was already on.
If you wish to use AJAX to have JavaScript submit the data to the server, it could easily be done behind the scenes.
Copy link to clipboard
Copied
OK Ian, I think my original post needs a little clarification:
I can't think of any way this could be done without the cooperation of the merchant whose cart is being modified – but who knows?. Am I dreaming of something impossible here?
Carlos
Copy link to clipboard
Copied
You need some co-operation from the merchant.
From a programming perspective, you could have your user submit to a page that runs in a very small iframe. That page can use cfhttp to talk to the merchant page.
Copy link to clipboard
Copied
Just what I suspected. But you never know until you ask, right?
Thank you very much, Ian and Dan for your help.
Carlos
Copy link to clipboard
Copied
As Dan indicates, there are lots a ways stuff like this can be done...
But you have to clearly understing and explain how the various comunications between the various systems are going to occure.
There are inline frames, redirects, cfhttp, AJAX, and web services just to name a few of the possibilities of the techniques and technologies that could be tapped for requirements like this.
But this level of abstraction takes a good, clear understanding of what happens on the client, what happend on your server what happens on the merchants server and how do each of these layers comunicate with each other.
Copy link to clipboard
Copied
<cfhttp method="Post" url="http://address.of.target.site/page-on-target-site?variable=value&variable_2=value_2&variable-3=value_3&etc=etc">
<cfhttpparam type="CGI"
value="a"
name="a"></cfhttp>
This should do what you are asking.
You can load all of the variables and values of those variables (order numbers, product id, price, etc) directly into the url= part of the cfhttp line.
You then create the cfhttpparam line exactly as I have it above.. because, for whatever reason, cfhttp likes to throw an error if there are no cfhttpparam's set - even if those parameters are meaningless. The one I have above basically creates an a=a parameter, which (unless the target site actually uses 'a' as a variable name) should be meaningless, yet allow the cfhttp code to function.
I use code like this to automatically load xml sitemaps for pages to a variety of sites that use them to index for search engines and rss feeds. It causes the 'insert' to work just fine, without ever showing anything on the users browser that it even happened at all.
If you need to verify that things are working correctly while you test this out, simply add the following snippet of code after the cfhttpparam tag:
<cfoutput>
File Content:<br>
#cfhttp.filecontent#<br>
</cfoutput>
This will cause whatever results that normally would be displayed on the 'target web page' (if the information was being put into that page directly ON that target page instead of 'remotely') to show up on your page. Once you're happy with the results, just delete the File Content snippet and you should be good to go.
WHeis