后加载页面
jQuery不重新加载页面的代码:
$(document).ready(function(){
$('#submit').click(function(){
var page = $(this).attr('id');
$('#content').load('content/submit.php');
});
});
表单提交
<input class="submit" id="submit" name="submit" type="submit" value="Submit">
submit.php
:
<div id="content">
<h2 style="color:#FF0000;"> Thanks For the Submission </h2>
</div>
我仍然不知道它在点击提交按钮
这将有助于您入门。
您需要通过阻止按钮上的默认事件来阻止正常表单提交。否则,由于表单提交,页面将重新加载。
您还需要将数据发送到服务器。您可以使用serialize()
获取所有表单数据
$(function(){
$('#submit').click(function(event){
event.preventDefault();
// collect the form data
var data = $(this).closest('form').serialize();
// send the data and load new content
$('#content').load('content/submit.php', data, function(){
// new html now exists can run any code needed here
});
});
});