Expected Behavior
01 - The form is published using jQuery.
02 - authorization is being processed.
03 - A MongoDB request is executed.
04 - Results should be returned instead of the form.
Actual behavior
Steps 1 to 3 are completed, but step 4 is not performed; correct results are returned, but on a blank page.
The form
<form name="login" id="login"> <p>username</p> <p>password</p> <input type="text" name="username" /> <input type="password" name="password" /> <button type="submit">login</button> </form>
JQuery
<script> $(document).ready(function() { $('#login').submit(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: '/login', data: $(this).serialize(), dataType: 'json', success: function(results) { $("#content_area").html(""); $("#content_area").append(results.content); } }); }); }); </script>
Python
@post('/login') def login(): """Authenticate users""" username = post_get('username') password = post_get('password') aaa.login(username, password, fail_redirect='/login') dbname = 'mydb' connection = pymongo.MongoClient(os.environ['OPENSHIFT_MONGODB_DB_URL']) db = connection[dbname] collection = db.myCollection href = 'my-title' query = {'title':href} projection = {'_id':0,'content':1} cursor = collection.find_one(query,projection) response.content_type = 'application/json' return dumps(cursor)
source share