I have a resource from a third party vendor that serves through http
protocol only. When I include a script tag like this...
<script src="http://example.com"></script>
I get a javascript variable with the JSON data, similar to this...
var data = {"total": "10", "results": [{"name": "Joe", "title": "developer"}, {"name": "Jane", "title": "engineer"}]};
I can then use the variable data
in my page to output results, etc.
The problem is, I need to serve this data on a page over SSL (https
) and I cannot make a resource request through http
for an https
page - meaning the <script/>
include does not work.
As a solution I am requesting the resource from a server page, lets say data.cfm
for example, then re-serving the JS variable through https
from my server. So, in this case, I'd like a request to https://anotherserver.com/data.cfm
to serve the same JS as http://example.com
<cfhttp result="myData" method="GET" charset="utf-8" url="http://example.com">
<cfoutput><pre>#myData.fileContent#</pre></cfoutput>
I should also note that the JSON data has HTML tags in it.
When I try to go to https://anotherserver.com/data.cfm
I get the data, but it is not formatted correctly. For example, hyperlinks are active as hyperlinks.
I also tried using <cfdump>
which returns the data as an unformatted string, but when I use the <script src="https://anotherserver.com/data.cfm"></script>
tag I do not get the JS variable.
Update
With further testing, I found that if I just copy the data as text in 2 files: data.cfm and data.js the js file works as expected and the cfm file does not. This leads me to believe that the file extension is causing the resource to be read as html. So, it's really more of a Coldfusion question. How can I set the cfm file to be read as javascript by the browser? Is there some response header or metadata field that will accomplish this?