---
title: "关于JS异步刷新"
author: "simple_hui"
date: "2010-11-20T19:49:22Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2010-11-20T19:49:22Z"
id: 818145
url: "https://simple-hui.iteye.com/blog/818145"
---

1.页面上<div id ="iframe" >显示新的请求页面</div>
  页面请求：javaScript:onlink(url);
2.js脚本
function createXMLHttpRequest(){
 if(window.ActiveXObject){
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = false;
    }
   }else{
 //其他浏览器
   xmlHttp = new XMLHttpRequest();
  } 
}

function onshow(){
 if(xmlHttp.readyState==4){
   if(xmlHttp.readyState==200){
    var info = xmlHttp.responseText;
    doucment.getElementById("iframe").innerHTML = info;
   }
 } 
}

function onLink(url){
 createXMLHttpRequest();
 xmlHttp.open("post",url,true);
 xmlHttp.onreadyStatechage = onshow();
 xmlHttp.send(null);
}