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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章