JS--原生JS如何用Ajax返回数据
程序员文章站
2022-03-01 17:42:44
...
实例
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <body> </body> <script type="text/javascript"> //1.创建请求 var ajax = new XMLHttpRequest(); //2.建立连接 ajax.open('get','./ajax.php',true); //3.发送请求 ajax.send(); //4.准备一个事件处理回来的内容 ajax.onreadystatechange = function(){ if(ajax.readyState == 4 && ajax.status ==200){ var result = ajax.responseText; alert(result); } } </script> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
上一篇: ubuntu 安装微信开发者工具