jquery ajax form表单ajax提交

第一步设置form 的id为#ajaxForm;
结束;

<script type="text/javascript">
	$(function () 
	{
		var options = 
		{
			url: "http://www.xxxxx.com/xxx.php", //提交地址:默认是form的action,如果申明,则会覆盖
			type: "post",   //默认是form的method(get or post),如果申明,则会覆盖
			success: fomsuccess,  //提交成功后的回调函
			dataType: "json", //html(默认), xml, script, json...接受服务端返回的类型
			clearForm: true,  //成功提交后,是否清除所有表单元素的值
			resetForm: true,  //成功提交后,是否重置所有表单元素的值
			timeout: 3000     //限制请求的时间,当请求大于3秒后,跳出请求
		};
		$("#ajaxForm").ajaxForm(options);
		function fomsuccess(data)//回调函数,data返回数据
		{
			if(data==1){
				alert('添加成功');
				window.location.reload();
			}
		}
	
	});
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章