//$.get()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="jquery-1.8.3.min.js"></script>
<body>
<input type="button" id="btn" value="发送一个ajax请求">
<div id="box"></div>
</body>
<script>
// var username = "yanweijuan";
// var age = "18";
// alert(1);
$("#btn").click(function(){
$.get("index.php",{"username":"yanweijuan","age":"18"},function(data){
$("#box").html(data);
})
})
</script>
</html>
<?php
/****
author:ywj;
****/
header("Content-type:text/html;charset=utf8");
echo "haha ,get!";
print_r($_GET);
?>
//$.post()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="jquery-1.8.3.min.js"></script>
<body>
<input type="button" id="btn" value="发送一个ajax请求">
<div id="box"></div>
</body>
<script>
$("#btn").click(function(){
$.post("index.php",{"username":"yanweijuan","age":16},function(data){
$("#box").html(data);
})
})
</script>
</html>
<?php
/****
author:ywj;
****/
header("Content-type:text/html;charset=utf8");
echo "haha ,post!";
print_r($_POST);
?>
//$.ajax()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="jquery-1.8.3.min.js"></script>
<body>
<input type="button" id="btn" value="发送一个ajax请求">
<div id="box"></div>
</body>
<script>
alert(1);
$("#btn").click(function(){
$.ajax({
'url':'index.php',
'data':{'username':'yan','age':16},
'success':function(data){
$("#box").html(data);
},
'dataType':'html',
// 'type':'get'
'type':'post'
});
});
</script>
</html>
<?php
/****
author:ywj;
****/
header("Content-type:text/html;charset=utf8");
echo "haha";
$print_r($_GET);
print_r($_POST);
?>