$.ajax異步操作的get或post提交,在我此時的項目中特別常用,下面我就整理了一下,進行一下小結。
第一種形式:get形式。
$.ajax({
Url:"",
Type:"get",
Data:{
operType:"query",
listType:"AgreementType"
},
dataType:"json",
Success:function(data){
Alert("成功後相應的操作!");
},
Error:fucntion(error){
Alert("操作失敗的操作 !");
}
});
第二種形式:post形式。
$.ajax({
Url:"../Handler/AgreementHandler.ashx",
Type:"post",
Data:{
operType: "query",
listType:"AgreementType"
}
dataType:"json",
Success:function(data){
Alert("成功後相應的操作!");
},
Error:function(error){
Alert("操作失敗的操作 !");
}
});
第三種形式:包含get或post操作的,混合模式。
$.ajax({
//這種是一種get提交
Url:"../Handler/AgreementHandler.ashx?userName=huxiaojie&password=123456",
Type:"post",
//post提交
Data:{
operType: "query",
listType:"AgreementType"
}
dataType:"json",
Success:function(data){
Alert("成功後相應的操作!");
},
Error:function(error){
Alert("操作失敗的操作 !");
}
});
這三種模式是我開發中經常用到的,他們用的是一套模板,只是他們的提交方式有所不同。
小結:
get和post的區別:
|
get |
post |
效率問題 |
效率較高。 因爲它把參數數據隊列提交表單的action屬性所指的URL中。 |
通過HTTP post機制,將表單內各個字段與其內容防止在HTML Header內一起傳送到action屬性所指的URL地址。 |
數據量問題 |
傳送的數據量較小,不能大於2kb |
數據量較大 |
安全問題 |
不安全。1)url中的參數過沒有經過加密處理時候,可以從中獲取數據;2)存在緩存的問題 |
較安全。不會想get那樣不安全 |
獲取數據方式 |
Request.Querystring["變量"] |
Request["變量"]或request.Form["變量"] |
這一塊的知識,還很欠缺,也在不斷的學習當中;如果有錯誤,敬請指正。