我正在使用 google app engine 1.8.0 (Python 2.7.5) 并且想要将数字发送到服务器(Ajax),它会通过乘法将其加倍并返回值。代码有什么问题?如何正确地做这个简单的事情?查了网上的教程,但它们更像是“简单的指南,如何通过 6 个简单的步骤为火星车搭建一个轮子”:D 然而最基本的简单的东西很难掌握。
HTML 代码:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
</head>
<body>
<script>
function TestingStuff() {
$.ajax({
url: "/DoubleMumbers",
type: "post",
data: { valueNr: $("data").val() },
success: function(){
alert('succes!');
}
});
}
</script>
<div>Enter the number:
<input id="data" type="text"/>
<input id="doubleNumber" type="button" onclick="TestingStuff()" value="Double">
<input id="result" type="text"/>
</body>
</html>
Javascript 代码(与 html 代码分开复制):
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script>
function TestingStuff() {
$.ajax({
url: "/DoubleMumbers",
type: "post",
data: { valueNr: $("data").val() },
success: function(){
alert('succes!');
}
});
}
</script>
GAE 代码(Python):
import webapp2
page = """
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
</head>
<body>
<script>
function TestingStuff() {
$.ajax({
url: "/DoubleMumbers",
type: "post",
data: { valueNr: $("data").val() },
success: function(){
alert('succes!');
}
});
}
</script>
<div>Enter the number:
<input id="data" type="text"/>
<input id="doubleNumber" type="button" onclick="TestingStuff()" value="Double">
<input id="result" type="text"/>
</body>
</html>"""
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write(page)
class DoubleNumbers(webapp2.RequestHandler):
def post(self):
self.response.out.write(valueNr*2)
app = webapp2.WSGIApplication([
('/', MainHandler),
('/DoubleNumbers', DoubleNumbers)
], debug=True)
代码中可能有错误,只是头已经晕了,试图弄清楚完成这项工作所需的基本内容。任何意见将不胜感激。