Access data from Google App Engine datastore in javascript file

What are the options for accessing information from the Google App Engine data store in a javascript file?

BACKGROUND:

I am running an application in the Google App Engine that uses the Google Graphics Tools API. All the data that I would like to display is in my Google App Engine data store.

WHAT I GOT

I can access the data in my python script. Also, in a python script, I encode data in JSON. My idea was to save this in a js file that I could import into HTML, and then build a diagram there. However, this does not work because writing to local files is not supported in App Engine.

+4
source share
3 answers

XMLHttpRequest

From python file: Write JSON data in URL. In App Engine, this is done using

self.response.write(data) 

From Javascript, make an XHR request as follows:

 function getData() { var dataObject = new XMLHttpRequest(); dataObject.open('GET', 'URL', true); dataObject.send(); return dataObject; } 

This will return an XMLHttpRequest object with the data in the string in the response or responseText attribute.

+1
source

In App Engine, you usually create an HTML page that you serve for the client. You do not need to save JSON in a js file, you can embed it directly as text in the HTML page that you serve for your client.

+1
source

You can use something like jersey to create a REST api for the backend. This is a bit of work. You can also make a GWT application with the appengine project, which really has a very simple backend connection. You can then link this to your javascript application or use the hooks your javascript application can use.

+1
source

All Articles