?
This document uses PHP Chinese website manual Release
通過遠程 HTTP GET 請求載入信息。
這是一個簡單的 GET 請求功能以取代復雜 $.ajax 。請求成功時可調用回調函數。如果需要在出錯時執(zhí)行函數,請使用 $.ajax。
jQuery 1.12 中 jQuery.post 和 jQuery.get 支持對象參數,這樣一來好處還比較多,比如設置回調函數的context,或者跨域 post 時可以withCredential: true。用法可以參考最后一個示例。
url:待載入頁面的URL地址
data:待發(fā)送 Key/value 參數。
callback:載入成功時回調函數。
type:返回內容格式,xml, html, script, json, text, _default。
請求 test.php 網頁,忽略返回值。
$.get("test.php");
請求 test.php 網頁,傳送2個參數,忽略返回值。
$.get("test.php", { name: "John", time: "2pm" } );
顯示 test.php 返回值(HTML 或 XML,取決于返回值)。
$.get("test.php", function(data){ alert("Data Loaded: " + data); });
顯示 test.cgi 返回值(HTML 或 XML,取決于返回值),添加一組請求參數。
$.get("test.cgi", { name: "John", time: "2pm" }, function(data){ alert("Data Loaded: " + data); });
jQuery 1.12 中 jQuery.get()支持對象參數,具體的參數可以參考 $.ajax():
jQuery.post({ url: “/example” });