Reputation: 123
I have a basic Google App Engine project using python. I would like to implement a sort of logging on my site (I do understand that google app engine has this kind of feature). Also in the future i would like to add high scores to some of my games using this same idea. For my logging i have a basic page.py that contains this:
from google.appengine.api import users
from google.appengine.ext import ndb
import webapp2
import json
class Save(ndb.Model):
time = ndb.DateTimeProperty(auto_now_add=True)
url=ndb.StringProperty()
user=ndb.StringProperty()
class MainPage(webapp2.RequestHandler):
def post(self):
data = json.loads()
self.stuff.url=(data)
self.stuff.put()
app = webapp2.WSGIApplication([
('/page.py', MainPage),
], debug=True)
This is a test before i implement the entire thing. I want to save the date, user, and page title in my logs. I know how to get the other things. I want jQuery in the html to send the page title to the python file. Here is my jQuery.
$.ajax({
type: "POST",
url: "/page.py",
dataType: 'json',
data: ('index')
})
I have a good understanding of html, this is the first time i have played with jQuery and json, I have a good understanding of python as well.
My questions. How is this ajax file transfer supposed to work? I need a parameter for json.loads() what would that be, how would it work? A simple example would be greatly appreciated.
I have done google searches and stack overflow searches, but i have not found a simple explanation and example.
Thanks in advance.
Elijah
Upvotes: 0
Views: 243
Reputation: 11706
You can use
class MainPage(webapp2.RequestHandler):
def post(self):
data = self.request.body
args = json.loads(data)
.... and put the data ....
But why not use: https://cloud.google.com/appengine/docs/python/endpoints/
Or start here: https://www.youtube.com/watch?v=uy0tP6_kWJ4
Upvotes: 1