Django/Jquery 新手:
尝试打印“感谢您注册!” 提交表单后。
<script type="text/javascript">
$(function() {
$("input[data-submit-item]").live("click", function() {
var message = "Thanks for signing up!";
$.ajax({
type: "POST",
url: "/add",
data: {
"text": $("#item").val(),
"csrfmiddlewaretoken": $('input[name~="csrfmiddlewaretoken"]').val()
},
success: function(data) {
$("#item-list").append(data);
$("#confmessage").append(message);
$("#item").val("");
}
});
});
});
</script>
</head>
<body>
<div id = "main-container">
<h1>FooBar Baz</h1>
<div id = 'signup-form'>
<form>
<input type="text" id="item" placeholder="Enter your email ..." />
{% csrf_token %}
<div><input type="submit" value="Sign Up" data-submit-item="true" /></div>
</form>
</div>
<div id = "confmessage"></div>
<p><strong>front</strong></p>
<ul id="item-list">
{% for item in line %}
<li>{{ item.text }}</li>
{% endfor %}
</ul>
<p><strong>back</strong></p>
<p><a href="/remove">remove</a></p>
</div>
</div>
</div>
</div>
</body>
</html>
这只是打印出所有输入电子邮件的列表,但不打印确认消息。这是此示例的修改:https ://github.com/memcachier/memcachier_line/blob/master/templates/index.html