日期:2014-05-16 浏览次数:20519 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title> button click test </title>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript">
function getdata(){
$.ajax({
url: "do.php", // 这里改成你要执行的php便可
success: function(data){
if(data.success==1){ // 根据返回的数据做不同处理
alert(data.msg);
}
}
});
}
</script>
</head>
<body>
<input type="button" onclick="getdata()" value="执行php">
</body>
</html>
<?php
$ret = array();
$ret['success'] = 1;
$ret['msg'] = '调用php成功';
header('content-type:application/json');
echo json_encode($ret);
?>