AJAx实现局部刷新

AJAX示例

                   window.οnlοad= function() {

                            varxhr;

                            if(window.XMLHttpRequest) {

                                     //IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码

                                     xhr= new XMLHttpRequest();

                            }else {

                                     //IE6, IE5 浏览器执行代码

                                     xhr= new ActiveXObject("Microsoft.XMLHTTP");

                            }

                            xhr.open("get","testAjax.txt");

                            alert(xhr.readyState);

                            xhr.send();

                            xhr.onreadystatechange= function() {

                                     alert(xhr.readyState);

                                     if(xhr.readyState == 4 && xhr.status == 200) { //返回完整,请求成功

                                               var res =xhr.responseText; //获取返回值

                                               //拿到返回值后可对dom操作,局部刷新页面

                                               alert(res);

                                     }

                            }

                   }

        

你可能感兴趣的:(AJAX)