JQuery Ajax's Load () load page method

Source: Internet
Author: User
Tags wrapper browser cache

The load () method uses the Get method by default, and the Post method is used if the data parameter is passed.

-Automatically converts to POST mode when additional parameters are passed. In JQuery 1.2, you can specify a selector to filter the loaded HTML document, and only the filtered HTML code will be inserted into the DOM. Syntax like "url #some > selector", the default selector is "body>*".

Explain:

Load is the simplest Ajax function, but the use has limitations:

1. It is primarily used for AJAX interfaces that return HTML directly
2.load is a jquery wrapper set method that needs to be invoked on the jquery wrapper set, and the returned HTML is loaded into the object, even if the callback function is set. The load interface is designed to be smart and easy to use. The following example demonstrates the use of the load interface:

Load () function:

Function Description: Load (URL, [data], [callback]) return value: JQuery

Parameter description:

URL: To be loaded into the HTML Web site.

Data: (optional parameters) sent to the server's key/value.

Callback: (optional parameter) The callback function when it is successfully loaded.

Here's an example demo:

First, create the test.html file you want to load:

The code is as follows Copy Code


<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>ajax Demo </title>
<body>
PHP Point-and-click (www.111cn.net), Focus on PHP development, provide professional web development tutorials!
</body>

Then create the ajax.html file and remember to introduce jquery.

The code is as follows Copy Code


<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

<script type= "Text/javascript" src= "/jquery-1.7.1.min.js" ></script>
<script>
$ (document). Ready (function () {
$ ("#btn"). Click (function () {
$ ("#result"). Load ("test.html", function (responsetext,textstatus) {
$ ("#display"). Append ("$ ("#display"). Append ("});
});
});
</script>
<body>
<input type= "button" value= "Test" id= "btn"/>
The contents of <div id= "Result" ></div>
<div id= "Display" ></div>
</body>

The above example shows how to use the Load method.

Tip: We need to keep an eye on the browser cache and add a timestamp parameter (NET Date ()) When using the Get method. GetTime () to ensure that each URL is sent differently, you can avoid browser caching.

Tip: When you add a space after the URL parameter, such as "", there will be an "unrecognized symbol" error, the request can be sent normally. However, HTML cannot be loaded into the DOM. Resolution of the problem after deletion.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.