当用户点击按钮时,一切正常。但是当他们进入时,页面只是重新加载。我究竟做错了什么?AJAX表单提交输入
这里是我的全码:
<!doctype html>
<html>
<head>
<title>Fun!</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="" media="print" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<style type="text/css">
body {
font-family: arial;
}
</style>
<script type="text/javascript">
function get() {
$.post('data.php', { name: form.name.value },
function(output) {
$('#age').html(output).show();
}
);
}
</script>
</head>
<body>
<div class="container">
<form action="" name="form" method="post">
<input type="text" name="name" /> <input type="button" value="Get" onClick="get();" />
</form><br />
<div id="age" style="display: none;">Result</div>
</div>
</body>
</html>
感谢。
感谢您的帮助,但它仍然只是重新加载页面。 '<形式行动= “” 名称= “形式” 方法= “POST” 的onsubmit = “得到();”> \t \t \t \t <输入类型=“submit”value =“Get”/> \t \t \t
' 我错过了什么吗? – user1453094 2012-07-09 00:49:18
使用'onsubmit =“event.preventDefault(); get();”'。 'preventDefault();'防止提交表单的默认动作。 – 2012-07-09 00:51:31
非常感谢!作品。 :) – user1453094 2012-07-09 00:53:13