I have a template set up that I’m making ajax calls to via jQuery. I’m passing a URL parameter called “method” and then doing a <cfswitch> through each method to determine what block of code to execute.
Problem is, I don’t want this page to be accessible outside of the ajax call. In other words, I don’t want the template to run if someone just types the URL into their browser.
Is there a way to do that? I thought in .php there was a way to tell what type of request it was. Does anything like this exist in Coldfusion? Or any suggestions?
jQuery injects the request with a
X-Requested-Withheader set with the value “XMLHttpRequest”. In coldfusion, you can view this by dumping the HTTP Request:So, all you need to do is test for that header, for example: