﻿/*
示例
function callBack()
{
locatiion.reload(true);
}
	
new Ajax("/index.aspx", "a=1&b=2", callBack, "post", ”delete");
0:	请求地址
1:	查询字符串（不包含"?"和操作名）,字符串类型参数必须经过encodeURIComponent处理，不可以使用escape
2:	回调函数
3:  请求方式，"post" 或者 "get"
4： 操作名
create_date:2008.10.9
author:stupidliao
*/
function Ajax(url, params, callBack, method, optName)
{
    var xhr = null;
    if (self.XMLHttpRequest)
    {
        xhr = new XMLHttpRequest();
    }
    else
    {
        xhr = new ActiveXObject('Msxml2.XMLHTTP') || new ActiveXObject('Microsoft.XMLHTTP');
    }
    this.stateChange = function()
    {
        if (xhr.readyState == 4)
        {
            if (callBack && typeof callBack == "function")
            {
                callBack(xhr.responseText);
            }
        }
    };

    if (method.toUpperCase() == "GET")
    {
        xhr.open(method, url + "?" + params + "&ajaxMethod=" + optName + "&random="+Math.random(), true);

    }
    else
    {
        xhr.open(method, url, true);

    }
    xhr.onreadystatechange = this.stateChange;
    xhr.setRequestHeader("QIDIANSNSAJAX-Ver", "ver1.0");
    if (method.toUpperCase() == "GET")
    {
        xhr.send("");
    }
    else
    {
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.send(params + "&ajaxMethod=" + optName);
    }
}