Home > Web Front-end > JS Tutorial > body text

Detailed explanation of jquery load method usage

巴扎黑
Release: 2017-06-30 14:25:21
Original
1710 people have browsed it

jquery load is a function in jquery ajax. Load can conveniently and quickly load a page directly into the specified p (html, php), and it can take parameters. Let me tell you Detailed introduction to the usage of the load method.


Format

load(url,data,function(response,status,xhr))

How to use data

1. Load a php file that does not contain passing parameters

The code is as follows Copy code
$("#myID").load("test.php");

//Import the result after running test.php in the element with ID #myID
2. Load a php file that contains a passing parameter

The code is as follows Copy code

$("#myID").load("test.php",{"name" : " Adam"});

//The imported php file contains a passing parameter, similar to: test.php?name=Adam

or directly

$("# pResult").load("jqueryLoad?username=" + username + "&un="+$("#username").val()+"×tamp=" + (new Date()).getTime());

When sending parameters, the parameters must be encoded twice:

The code is as follows Copy code

var username = encodeURI(encodeURI($("#username").val()));


Use AJAX request to change the text of p element:

The code is as follows Copy code

$("button").click(function(){
$("p").load('demo_ajax_load.txt');
});


How to use callback

For example, if we want to slowly display the loaded content after the load method gets the server response, just You can use the callback function. The code is as follows:

The code is as follows Copy code

$("#go") .click(function(){

$("#myID").load("welcome.php", {"lname" : "Cai", "fname" : "Adam", function(){

$("#myID").fadeIn('slow');}

);

});

例子

 代码如下 复制代码





jQuery load方法 演示



  

 

   
 

jQuery load方法 演示

 

姓: 




名: 
  





 

 


显示代码

 


Note: Only if the load processing function is bound before this element is completely loaded, it will be triggered after it is loaded. If you bind it later, it will never trigger. So don't bind the load event in $(document).ready(), because jQuery will bind the load event after all DOM loading is completed

The above is the detailed content of Detailed explanation of jquery load method usage. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!