AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。
先创建两个文件,一个作为服务器端页面文件,一个作为web端页面文件。
分别是ajax.php,ajax.html.
ajax.php
<?php $fp = fopen("./02.txt","a");//打开一个文件 fwrite($fp,"PHP_ _ _");//往打开的文件里面写入“PHP_ _ _” fclose($fp); ?>
ajax.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function f1(){
//利用ajax请求ajaxfile.php
//1,创建ajax对象
var xhr = new XMLHttpRequest();
//2.创建新的http请求
xhr.open('get','./ajax.php');
//3.发送请求
xhr.send(null);
}
</script>
</head>
<body>
<h2>ajax对服务器发送请求</h2>
<input type="button" value="触发" onclick="f1()"/>
</body>
</html>