4

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

BACKGROUND:

I am running an app on Google App Engine which uses the Google Chart Tools API. All the data which I would like to graph is in my Google App Engine datastore.

WHAT I'VE TRIED

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

2
  • Is the channel api not an option/applicable? my first thought: send the data to memcache and with a channel and a python handler send the json to the client side JS...but that's just a first thought mind you. Commented Mar 7, 2013 at 4:49
  • It seems that the channel api is an option, but it might be overkill for what I am doing. The channel api creates a persistent connection for updating information immediately, where as my application will not need to send users such updates. Commented Mar 7, 2013 at 5:19

3 Answers 3

1

On App Engine you typically generate an HTML page that you serve to a client. You don't need to save your JSON to a js file, you can embed it directly as text into your HTML page that you serve to your client.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use something like Jersey to create a REST api for the backend. It's a bit of work. You can also make a GWT application with the appengine project, which has really extremely easy backend hookups. Then you can interface this with your javascript application or have hooks that your javascript application can use.

Comments

1

XMLHttpRequest

From the python file: Write the JSON data to a URL. In App Engine, this is done with

self.response.write(data)

From the Javascript, make the XHR request like this:

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

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

1 Comment

To be clear, the returned object won't have the data yet. You need to use the onreadystatechange event to handle the data being received. See w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.