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>

 

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2021-07-16
  • 2022-12-23
  • 2021-10-31
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-02-12
  • 2021-10-27
  • 2022-01-12
  • 2021-12-02
相关资源
相似解决方案