【www.gdgbn.com--jquery】

普通的调用方法很简单

$("#index_foot_container").load("foot.html");

分析,一般引起load乱码是由于二者页面编码不致影起的,处理方法是

1.我的显示页面index.html的编码是uft-8的;
2.我的静态页面foot.html的编码是uft-8的;

jquery官网介绍

绑定给window对象,则会在所有内容加载后触发,包括窗口,框架,对象和图像。如果绑定在元素上,则当元素的内容加载完毕后触发。

注意:只有当在这个元素完全加载完之前绑定load的处理函数,才会在他加载完后触发。如果之后再绑定就永远不会触发了。所以不要在$(document).ready()里绑定load事件,因为jquery会在所有dom加载完成后再绑定load事件。

 

调用load方法的完整格式是:load( url, [data], [callback] ),

 

version added: 1.0.load( url, [ data ], [ complete(responsetext, textstatus, xmlhttprequest) ] )
urla string containing the url to which the request is sent.

dataa map or string that is sent to the server with the request.

complete(responsetext, textstatus, xmlhttprequest)a callback function that is executed when the request completes.


$("#result").load("ajax/test.html", function() {
  alert("load was performed.");
});

一些load常用方法

如何使用data

1.加载一个php教程文件,该php文件不含传递参数$("#myid").load("test.php");

//在id为#myid的元素里导入test.php运行后的结果
2. 加载一个php文件,该php文件含有一个传递参数

$("#myid").load("test.php",{"name" : "adam"});

//导入的php文件含有一个传递参数,类似于:test.php?name=adam
3. 加载一个php文件,该php文件含有多个传递参数。注:参数间用逗号分隔

$("#myid").load("test.php",{"name" : "adam" ,"site":"61dh.com"});

//导入的php文件含有一个传递参数,类似于:test.php?name=adam&site=61dh.com
4. 加载一个php文件,该php文件以数组作为传递参数

$("#myid").load("test.php",{"myinfo[]", ["adam", "61dh.com"]});

//导入的php文件含有一个数组传递参数。
注意:使用load,这些参数是以post的方式传递的,因此在test.php里,不能用get来获取参数。

本文来源:http://www.gdgbn.com/wangyezhizuo/29840/