1.最原始的js ,new xmlhttprequest(); //由於瀏覽器相容的原因,**複雜,多使用基於jquery的非同步請求方法(內部封裝)
2.基於jquery的ajax方法:
(1)load(url,[data],[callback]),例項如下:
$("#test").load("test.php",,function());
(2)$.getjson(url,[data],[callback]),例項如下:
$.getjson("test.php", , function(data));
(3)$.get(url,[callback]),例項如下:
$.get("test.php", , function(data));
(4)$.post(url,[data],[callback]),例項如下:
$.post("test.php", , function(data));
(5)$.ajax(),例項如下:
$.ajax(,//傳送到伺服器的引數
datatype:"json",//伺服器響應的資料型別
success:function(data)
});以上幾種方法都等價於$.ajax()方法,除此之外還有其他的基於jquery的非同步請求方法。
http請求的幾種方法
1.get 傳送請求來獲得伺服器上的資源,請求體中不會包含請求資料,請求資料放在協議頭中。另外get支援快取 快取 可保留書籤等。冪等 2.post 和get一樣很常見,向伺服器提交資源讓伺服器處理,比如提交表單 上傳檔案等,可能導致建立新的資源或者對原有資源的修改。提交的資源放在請求體中。不支援快...
請求引數獲取的幾種方法
1 使用 pathvariable 註解 public modelandview helloworld pathvariable string id,pathvariable string str pathvariable 也可以獲取 含正規表示式的一類值 例如 public void handle...
非同步請求的幾種方式
1.最原始的js new xmlhttprequest 由於瀏覽器相容的原因,複雜,多使用基於jquery的非同步請求方法 內部封裝 2.基於jquery的ajax方法 1 load url,data callback 例項如下 test load test.php function 2 getjs...