1
我试图弄清楚如何使用jQuery AJAX与Python的瓶模块。jQuery和表单POST差蟒蛇瓶
我已经创建了一个包含两个按钮,一个的jQuery控制,另一种形式的提交按钮里面一个非常基本的页面。两个按钮只是发送一个POST请求到一个瓶子服务器,它应该用“完成!”来回应。信息。
这是模板的代码:
<!DOCTYPE html>
<html>
<head>
<title>Test Template</title>
<!-- JQuery JS -->
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(document).ready(function() {
$('button').on('click', function(){
$.post("/home");
});
});
</script>
</head>
<body>
<button>Submit</button>
<form action="/home" method="post" enctype="multipart/form-data">
<input type="submit" value="Submit" />
</form>
</body>
</html>
这是瓶子服务器的代码:
from bottle import route, run, template
@route('/home')
def home():
return template('template')
@route('/home', method='POST')
def homePost():
return "Done!"
run(host='localhost', port=8080, debug=True)
run(reloader=True)
为什么点击表单按钮正确返回信息,但点击了jQuery一个什么都不做? jQuery是否阻止瓶子的回应?
感谢您的帮助。
Pablo
水晶清楚!非常感谢7stud。 – MonkeyButter