﻿// JScript 文件
//声明XMLHttpRequest对象
//调用示例
/*function ch()
    {
    var url="default.aspx"
    Asynchronous(url);
    }
    function msgFunction(m)
    {
        //alert(m);
     document.getElementById("test1").innerHTML=m;
    }

*/
var xmlHttp1;
/*创建对象*/
function createXMLHTTP()
{
    if(window.ActiveXObject)
        xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
    else if(window.XMLHttpRequest)
        xmlHttp1 = new XMLHttpRequest();
    /*if(window.XMLHttpRequest)
    {
        xmlHttp1=new XMLHttpRequest();//mozilla浏览器     }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本         }
        catch(e)
        {}
        try
        {
            xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本         }
        catch(e)
        {}
        if(!xmlHttp1)
        {
            window.alert("不能创建XMLHttpRequest对象实例！");
            return false;
        }
    }*/
}
/*异步操作的页面*/

function Asynchronous(path,dataxml)
{
    var strurl = "http://www.jehuo.com/"+path;
//	alert(strurl);
//	alert(dataxml);
    createXMLHTTP();/*创建XMLHttpRequest对象*/
    xmlHttp1.open("post",strurl,false);
    xmlHttp1.onreadystatechange=CallBackFunction;
    xmlHttp1.send(dataxml);
}

/*回调函数*/
function CallBackFunction()
{	
//    alert(xmlHttp1.readyState);
//	alert(xmlHttp1.status);
//	alert(xmlHttp1.responseText);
    if(xmlHttp1.readyState==4)
    {
		
        if(xmlHttp1.status==200)
        {
             /*xmlHttp.responseText;*/
            msgFunction(xmlHttp1.responseText);   
        }
    }
}
/*带参数*/
function Asyn(url)
{
   
    createXMLHTTP();/*创建XMLHttpRequest对象*/
    xmlHttp1.open("post",url+"&timestamp="+new Date().getTime(),false);
    xmlHttp1.onreadystatechange= CallBackFunction1;
    xmlHttp1.send(null);
    return false;
}
function Asynchronous1(path,frm)
{
    writetoxml(frm);
    createXMLHTTP();/*创建XMLHttpRequest对象*/
    xmlHttp1.open("post",path+"?timestamp="+new Date().getTime(),false);
    xmlHttp1.onreadystatechange= CallBackFunction1;
    xmlHttp1.send(xmlDom);
    return false;
}

/*回调函数*/
function CallBackFunction1()
{
    if(xmlHttp1.readyState==4)
    {
        if(xmlHttp1.status==200)
        {
            /*xmlHttp.responseText;*/
           return msgFunction1(xmlHttp1.responseText);   
        }
    }
}

function writetoxml(frm)
{
    loadxml("<?xml version=\"1.0\" encoding=\"gb2312\"?><root></root>");
    for(var icount=0; icount<frm.length; icount++)
    {
        createElement(frm[icount].id,frm[icount].value);
    }
}

  
