In using Google Apps Script as a jSONP proxy, I covered how you could use GAS to get over javaScript same domain restrictions. If you need to access jSon data from javaScript, jQuery and so on, and your script is running locally or the data in a different domain than your script, unless the data hosting platform supports jsonp, you are going to find it difficult to access that data from javaScript.
You can access this as in this jQuery example.
$.getJSON(proxyJsonp + "?url=" + url + "&callback=?", null, function(data) { ... deal with data returned in ... jQuery.parseJSON(data.results) });
where
- url is the address of your (non-jsonp capable) data .. for example
- proxyJsonp is the shared url of your Google Apps script jsonp faker. There’s one at https://script.google.com/a/macros/mcpher.com/s/AKfycbzGgpLEWS0rKSBqXG5PcvJ7Fpe02fvGqiCqq54SVQmBJSpy_6s/exec
Caching with Google Apps Script
Another benefit of ‘faking’ jSonP by using Google Apps Script is that you can use the Google Caching service. This means that multiple urlFetches() to slower hosting platforms can be avoided since the GAS jsonP faker will cache data with the same URL. For details of how this works, see using Google Cache.