Latest web development tutorials

jQuery load () method

jQuery AJAX Methods jQuery AJAX Methods

Examples

The load file "demo_test.txt" content to the specified <div> element:

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

try it"

Definition and Usage

load () method to load data from the server, and places the returned data to the specified element.

Note: there is a jQuery called load the event method. Which, depending on the parameters of the call.


grammar

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

参数 描述
url 必需。规定您需要加载的 URL。
data 可选。规定连同请求发送到服务器的数据。
function(response,status,xhr) 可选。规定 load() 方法完成时运行的回调函数。

额外的参数:
  • response - 包含来自请求的结果数据
  • status - 包含请求的状态("success"、"notmodified"、"error"、"timeout"、"parsererror")
  • xhr - 包含 XMLHttpRequest 对象


Examples

More examples

Generate AJAX request, and sends the data via the request
How to use data parameters via AJAX request to send data (in this example in our AJAX tutorial are explained).

Generate AJAX request and use a callback function
How to use the function parameter data processing results from AJAX request.

Generate AJAX request with errors
How to use the function parameters to process the AJAX request error (using XMLHttpRequest parameter).


jQuery AJAX Methods jQuery AJAX Methods