第一步設定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>