实例
<!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"> //异步请求,是指主程序运行的过程当中,请求程序正常运行 //同步请求,主程序运行中,请求程序无法运行 //var ajax = new XMLHttpRequest(); //ajax.open('get','./ajax1.php',true); //ajax.send(); //ajax.onreadystatechange = function(){ // if(ajax.readyState == 4 && ajax.status ==200){ // var result = ajax.responseText; // alert(result); // } //} //alert('可以弹出的啊'); //同步请求,主程序等待操作 var ajax = new XMLHttpRequest(); ajax.open('get','ajax1.php',false); ajax.send(); var result = ajax.responseText; alert(result); alert('主程序代码'); </script> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例