load( url, [ data ], [ callback(responseText, textStatus, XMLHttpRequest) ] ):
load()方法的URL参数的语法结构为:“url selector”。注意,URL和选择器之间有一个空格。
load.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="jquery-2.0.3.js"></script>
<script>
$(function(){
$('#div1').load('data.html');
});
</script>
</head>
<body>
<div id="div1">
</div>
</body>
</html>
data.html
<li>100</li>
<li>200</li>
<li>300</li>
<div class = 'demo'>类选择器是demo的div</div>
如果只想加载类选择器是demo的div,则$('#div1').load('data.html .demo');在地址url后面加空格后,再使用选择器
默认请求是get
当有data参数时,默认是post方式:data形式{key:value}
$('#div1').load('2data.php',{"name":"hello"});
2data.php,当存在data参数时,php文件必须用$_POST接收参数
<?PHP
echo '<ul>
<li>'.$_POST["name"].'</li>
<li>200</li>
<li>300</li>
</ul>'
?>
如果PHP文件中用$_GET接收参数,则参数要写在url中,此时默认是get请求
$('#div1').load('2data.php?name=hello');