Ajax学习笔记(二)
一、Ajax请求——GET <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <h1>Ajax 发送get 请求</h1> <input type="button" value="发送get_ajax请求" id='btnAjax'> <script type="text/javascript"> // 绑定点击事件 document.querySelector('#btnAjax').onclick = function () { // 发送ajax 请求 需要 五步 // (1)创建异步对象 var xmlhttp = new XMLHttpRequest(); // (2)设置请求的参数。包括:请求的方法、请求的url。 xmlhttp.open('GET', '001.php'); // (3)发送请求 xmlhttp.send(); //(4)注册事件。 onreadystatechange事件,状态改变时就会调用。 //如果要在数据完整请求回来的时候才调用,我们需要手动写一些判断的逻辑。 xmlhttp.onreadystatechange = function () { // 为了保证 数据 完整返回,我们一般会判断