Search code examples
javascriptpythongoogle-app-enginewebapp2

Partial page updates


i am currently writing a python web-application running on google-app-engine using the webapp2 framework. Since i am not the web-guy i need an advice how to solve the following problem:

Assumed i have a very simple web order system where you put some articles in the shopping card and proceed to the checkout form... On the checkout form i need to display the total cost of the order. The problem is that there is also a combobox where the customer can choose a shipping method. Each shipping method has its individual transportation costs.

The question is how can i calculate and update the total cost (including the selected shipping method and its transportation costs) without reloading the whole page? Doing the calculations with client side Javascript seems to be inappropriate solution the me. But who to do the calculation on the server-side without reloading the whole page?


Solution

  • You can have the browser ask for a partial update using jQuery. Since you are not the web-guy I assume someone else is. He will probably know how to do that. You can then have the server perform the calculations and return either a html fragment or the result in json format.

    You should have a look at the jQuery.load() method.

    For the appengine part it would look something like:

    class CalculateCost(webapp.RequestHandler):
        def get(self):
            shipping_method = self.request.get('shipping_method')
            # calculate your cost here
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('%d' % cost)