Skip to main content
2Charlie
Inspiring
February 2, 2016
Question

How do I reserve JSON data for .getJSON calls?

  • February 2, 2016
  • 1 reply
  • 1642 views

I'm able to use cfhttp to query the data. However, I'm not sure how to reserve this data for my jQuery .getJSON() calls. Since I can't do a CORS call with JavaScript, I believed an alternative is to use ColdFusion cfhttp calls. Any suggestion is much appreciated.

    This topic has been closed for replies.

    1 reply

    Brainiac
    February 2, 2016

    Not exactly sure what you are asking. I think you are asking how to use CF as a proxy server. This in and of itself is fairly easy but I think I would need to know more specifics as to why as simply proxy services might not be the best solution. Why can't you use CORS? Assuming CORS is really not an option, JSONP would be the next "standard" way to accomplish what I think you are asking. Need more details...

    2Charlie
    2CharlieAuthor
    Inspiring
    February 2, 2016

    Thanks, Steve. I probably don't use the correct terms but yes. I'm exploring other alternatives and I came across a thread in jQuery to suggest using CF as a proxy server. However, I have never done much with ColdFusion. I'm in the process of asking if the API provider have their servers CORS enable. If not, then I may have to resort to CF proxy server if there are no other better alternatives. Will you provide links/information on the JSONP option? I have tried using .getJSON and came across the No 'Access-Control-Allow-Origin' header is present on the requested resource error; thus, I'm in the hunt for a solution.

    Thanks again.

    2Charlie
    2CharlieAuthor
    Inspiring
    February 5, 2016

    To hide the API key, you will need to use CF to act as a proxy.

    If you want your application to behave like a Single Page Application (SPA) (e.g. content is updated or changed on the page without a full page refresh), then you'll need to use AJAX to make that happen.  If you don't mind the page refresh, then all the work can be done server-side.


    Can I use something like CFAjaxproxy for this? If so, will it hide my API key?