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.