要求:页面加载时自动提交表单 且不跳转。
我已测试手工点击按钮,不跳转。哪位大神帮我看看,下面这个为何不行?
要求:如题
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
//将form转为AJAX提交
function ajaxSubmit(frm, fn) {
var dataPara = getFormJson(frm);
$.ajax({
url: frm.action,
type: frm.method,
data: dataPara,
success: fn
});
}
//将form中的值转换为键值对。
function getFormJson(frm) {
var o = {};
var a = $(frm).serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
//调用
$(document).ready(function(){
$('#Form1').bind('submit', function(){
ajaxSubmit(this, function(data){
alert(data);
});
return false;
});
$('#Form2').bind('submit', function(){
ajaxSubmit(this, function(data){
alert(data);
});
return false;
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#autosubmit").click(function() {//button的click事件
$("#Form2").submit();
});
});
</script>
</head>
<body>
<form id='Form2' action='phpinfo.php' method='post' name = 'payform'>
<input type='text' name='money' value='100'/>
<input type="submit" value="提 交" id ="autosubmit"/>
</form>
</body>
</html>