jQuery - AJAX load() method

jQuery load() method

The load() method loads data from the server and puts the returned data into the selected element.

Syntax:

$(selector).load(URL,data,callback);

The required URL parameter specifies the URL you wish to load.

The optional data parameter specifies the set of query string key/value pairs sent with the request.

The optional callback parameter is the name of the function executed after the load() method is completed.

This is the content of the sample file ("demo_test.txt"):

jQuery AJAX 是个非常棒的功能!

这是段落的一些文本。


Load the content of the file "demo_test.txt" into the specified

element:

    php中文网(php.cn)   

使用 jQuery AJAX 修改文本内容

You can also add jQuery selectors to URL parameters.

The example loads the content of the element with id="p1" in the "demo_test.txt" file into the specified

element:

      

使用 jQuery AJAX 修改文本

The optional callback parameter specifies when The callback function to be allowed after the load() method completes. The callback function can set different parameters:

responseTxt - Contains the result content when the call is successful

statusTXT - Contains the status of the call

xhr - Contains the XMLHttpRequest object

The following example will display a prompt box after the load() method is completed. If the load() method has succeeded, "External content loaded successfully!" is displayed, and if it fails, the error message is displayed:

      

使用 jQuery AJAX 修改该文本


Complete example:

First create a text.html file:

    php中文网(php.cn) 
已有评论:
张三:

沙发。

李四:

板凳。

王五:

地板。

Create another Write an HTML file (the name can be arbitrary) into jQuery AJAX load() method:

    php中文网(php.cn)   


Continuing Learning
||
php中文网(php.cn)
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!