jQuery load()メソッド

❮jQueryAJAXメソッド

ファイル「demo_test.txt」のコンテンツを特定の<div>要素にロードします。

$("button").click(function(){
  $("#div1").load("demo_test.txt");
});

定義と使用法

load()メソッドはサーバーからデータをロードし、返されたデータを選択された要素に配置します。

注: loadと呼ばれるjQueryイベントメソッドもあります。どちらが呼び出されるかは、パラメータによって異なります。


構文

$(selector).load(url,data,function(response,status,xhr))

Parameter Description
url Required. Specifies the URL you wish to load
data Optional. Specifies data to send to the server along with the request
function(response,status,xhr) Optional. Specifies a callback function to run when the load() method is completed.

Additional parameters:
  • response - contains the result data from the request
  • status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr - contains the XMLHttpRequest object

自分で試してみてください-例


データを送信するdataパラメーターを使用してAJAXリクエストでデータを送信する方法(この例では、 AJAXチュートリアルで説明されている例を使用しています)


を使用する関数パラメーターを使用してAJAXリクエストのデータ結果を処理する方法。


作成する関数パラメーターを使用してAJAXリクエストのエラーを処理する方法(XMLHttpRequestパラメーターを使用)。


❮jQueryAJAXメソッド