﻿/*
运行方法

在适当的事件中执行
getContent(url,div_id)

url 为服务器响应文件
div_id 为要设置Ajax返回文本的DIV的ID

*/
var xmlhttp=initxmlhttp();
function initxmlhttp()
{
	var xmlhttp
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
        }
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function getContent(url,div_id)
{
    if(!div_id){
        div_id = 'content' ;
    }
	var e=document.getElementById(div_id);
	e.innerHTML="<p align='center' style='color:red'><br />正在加载数据，请稍候...</p>";
	url=url
	xmlhttp.open("GET",url,true);
	//return ;
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
				e.innerHTML=xmlhttp.responseText;
		}
		else if(xmlhttp.readyState==4 && xmlhttp.status==404){
			if(e) document.getElementById(div_id).innerHTML="<p align=center><br /><span style=color:red;>无法找到所请求的资源，请尝试刷新本页</span></p>";
		}
	}
	xmlhttp.send(null);
}

function getNew(url,func){
	
	url=url+"?"+new Date();
	xmlhttp.open("GET",url,true);
	//return ;
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			func(xmlhttp.responseText);			
		}
		else if(xmlhttp.readyState==4 && xmlhttp.status==404){
			;
		}
	}
	xmlhttp.send(null);
}
