完整的數據校驗需要前台頁面(JS)和後台程序分別做校驗
為了防止機器提交
通過為了簡單
采用AJAX +JSON 方式提交數據 與傳統提交數據 的比較
/* 表單提交
var ajaxSubmitFormData = {
form:false
debug:false
callback:false
dataType:
onSubmit:function(data){
//正在提交數據提示
}
onResponse:function(response){
//當數據返回時觸
}
onResponse
alert(
window
}
onResponse
//輸入驗證碼界面
var formId=ajaxSubmitFormData
if (!$(formId)
$(formId)
}
}
onResponse
var s=
//alert(data
for(var i=
s=s+data[i]
}
alert(s);
}
onResponse
if (data
window
}else{
alert(
}
}
};
$(document)
$(
//alert($(this)
var formId=$(this)
submitAjaxFormNow(
return false; // <
});
$(
var formId=$(this)
//alert($(this)
submitAjaxFormNow(
});
});
function initSubmitAjax(formId
var options= {
beforeSubmit: function(formData
if (ajaxSubmitFormData
var queryString = $
alert(
}
if ($
ajaxSubmitFormData
}
return true;
}
success:function (responseText
try{
if (ajaxSubmitFormData
alert(
}
if ($
ajaxSubmitFormData
}
ajaxSubmitFormData
ajaxSubmitFormData
//
responseText=responseText
//trim space
responseText=responseText
var response = eval(responseText)[
if (de ==
if ($
ajaxSubmitFormData
returnFunc(ssages);
}else{
if ($
ajaxSubmitFormData
}
}
//$(formId)
}
if (de ==
//保存當前
ajaxSubmitFormData
ajaxSubmitFormData
if ($
ajaxSubmitFormData
}
//$(formId)
}
if (de ==
if ($
ajaxSubmitFormData
}
//$(formId)
}
if (de ==
if ($
ajaxSubmitFormData
}
//$(formId)
}
}catch(e){
alert(
}
}
clearForm:true
resetForm:true
timeout:
type:
};
$(formId)
alert(
$
});
return options;
}
function submitAjaxFormNow(formId
if ($(formId))
$(formId)
}
function submitAjaxForm(formId
if ($(formId))
$(formId)
}
預覽
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27021.html