jQuery简单的Ajax调用示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="keywords" content="关键词1,关键词2">
<meta name="description" content="描述语句">
<title>文档标题</title>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<div id="myData">
<h2>改变文本内容</h2>
</div>
<button id="testAjax" type="button">Ajax改变内容</button>
<script type="text/javascript">
$(function(){
$("#testAjax").click(function(){
//初建ajax;
$.ajax({
//数据类型
type:"POST",
//链接地址
url:"test.php",
data:"name=garfield&age=18",
success:function(data){
$("#myData").html('<h2>'+data+'</h2>')
}
})
})
})
</script>
</body>
</html>
调用php后台数据
<?php $msg='hello,'.$_POST['name'].',you age is'.$_POST['age'].'!'; echo $msg; ?>

浙公网安备 33010602011771号