學習ajax教程,詳細了解get與post
get方式:
作用:可傳送簡單數(shù)據(jù)
大小:url最大長度是2083 bytes,可以用于get傳遞數(shù)據(jù)的長度是2048 bytes
包含體:數(shù)據(jù)追加到url中發(fā)送,也就是http的header傳送
post方式:
作用:可傳送簡單復雜數(shù)據(jù)
大小:web.config里限制
包含體:數(shù)據(jù)在http請求的實體內(nèi)容里傳送
ajax用post模式傳送數(shù)據(jù).需注意:
1.設置header的context-type為application/x-www-form-urlencode確保服務器知道實體中有參數(shù)變量.通常使用xmlhttprequest對象的setrequestheader("context-type","application/x-www-form-urlencoded;")
2.參數(shù)是名/值一一對應的鍵值對,每對值用&號隔開.如 name=abc&sex=man&age=18.
3.參數(shù)在send(參數(shù))方法中發(fā)送
4.服務器端請求參數(shù)區(qū)分get與post.例如asp.net中以request.form["name"]對實體中的參數(shù)請求.這時url參數(shù)請求request.querystring["name"]將引發(fā)異常
新聞熱點
疑難解答
圖片精選