我有一個Google App Engine,它有一個表單。當用戶點擊提交按鈕時,AJAX操作將被調用,並且服務器將輸出一些內容以附加到它所來自的頁面的末尾。如何,我有一個Django模板,我打算使用jQuery。我有以下看法:使用jQuery的Django模板:現有頁面上的Ajax更新
<html>
<head>
<title></title>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
</head>
<body>
welcome
<form id="SubmitForm" action="/" method="POST">
<input type="file" name="vsprojFiles" />
<br/>
<input type="submit" id="SubmitButton"/>
</form>
<div id="Testing">
{{thebest}}
</div>
</body>
</html>
下面是scripts.js中的腳本:
$(function() {
$("#SubmitForm").click(submitMe);
});
var submitMe = function(){
//alert('no way');
var f = $('#SubmitForm');
var action = f.attr("action");
var serializedForm = f.serialize();
$.ajax({
type: 'post',
data: serializedForm,
url: form_action,
success: function(result) {
$('#SubmitForm').after("<div><tt>" +
result +
"</tt></div>");
}
});
};
這是我的控制器代碼:
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.api.urlfetch_errors import *
import cgi
import wsgiref.handlers
import os
import sys
import re
import urllib
from django.utils import simplejson
class MainPage(webapp.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__), 'Index.html')
template_values={'thebest': 'thebest'}
tmplRender =template.render(path, template_values)
self.response.out.write(tmplRender)
pass
def Post(self):
print >>sys.__stderr__,'me posting'
result = 'grsgres'
self.response.out.write(simplejson.dumps(result))
正如你所看到的,在用戶點擊時在提交按鈕上,控制器方法Mainpage.post將被調用。
現在我想在表單後面顯示'result'變量的內容,我該怎麼做?