ajax简单创建代码
来源:互联网 发布:水电预算工作量软件 编辑:程序博客网 时间:2024/05/19 21:16
/*
* XMLHttpRequest object
*/
var xmlHttp;
/*
* Call back handler method
*/
var handlerMethod;
/*
* Response Data Type
*/
var responseDataType;
/*
* Initial a XMLHttpRequest object when page load.
*/
window.onload=pageLoad;
function pageLoad()
{
createXmlHttp();
}
/*
* Asynchronized send data to specified url
* url: the location to which date will be sent.
* queryString: queryString data which will be sent to server.
* method: sending method, "GET" or "POST".
* xml: xml data which will be sent to server.
* handler: call back handle function.
* type: response data type, "Text" or "XML".
*/
function sendData(url,queryString,method,xml,handler,type)
{
handlerMethod=handler;
method = method.toUpperCase();
responseDataType = type;
if(method == "GET")
{
url = url + "?" + queryString;
}
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = callback;
if(xml)
{
xmlHttp.setRequestHeader("Content-Type","text/xml");
}
else if (method == "POST")
{
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xml = queryString;
}
xmlHttp.send(xml);
};
/*
* Create and return a new XMLHttpRequest object
*/
function createXmlHttp()
{
try
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE6.0
if(!xmlHttp)
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); //IE 4.0,IE 5.0
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest(); //supported by other browsers.
}
}
catch(ex)
{
HandleException();
}
return xmlHttp;
};
/*
* Handle create XMLHttpRequest exception.
*/
function HandleException()
{
throw new Exception("XMLHttpRequest is not created!");
};
/*
* Handle the response from server
*/
function callback()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(responseDataType != "Text")
{
handlerMethod(xmlHttp.responseXML); //responseXML/Text is supposed by IE and Firefox,ResponseXML/Text only in IE
}
else
{
handlerMethod(xmlHttp.responseText);
}
}
}
};
* XMLHttpRequest object
*/
var xmlHttp;
/*
* Call back handler method
*/
var handlerMethod;
/*
* Response Data Type
*/
var responseDataType;
/*
* Initial a XMLHttpRequest object when page load.
*/
window.onload=pageLoad;
function pageLoad()
{
createXmlHttp();
}
/*
* Asynchronized send data to specified url
* url: the location to which date will be sent.
* queryString: queryString data which will be sent to server.
* method: sending method, "GET" or "POST".
* xml: xml data which will be sent to server.
* handler: call back handle function.
* type: response data type, "Text" or "XML".
*/
function sendData(url,queryString,method,xml,handler,type)
{
handlerMethod=handler;
method = method.toUpperCase();
responseDataType = type;
if(method == "GET")
{
url = url + "?" + queryString;
}
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = callback;
if(xml)
{
xmlHttp.setRequestHeader("Content-Type","text/xml");
}
else if (method == "POST")
{
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xml = queryString;
}
xmlHttp.send(xml);
};
/*
* Create and return a new XMLHttpRequest object
*/
function createXmlHttp()
{
try
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE6.0
if(!xmlHttp)
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); //IE 4.0,IE 5.0
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest(); //supported by other browsers.
}
}
catch(ex)
{
HandleException();
}
return xmlHttp;
};
/*
* Handle create XMLHttpRequest exception.
*/
function HandleException()
{
throw new Exception("XMLHttpRequest is not created!");
};
/*
* Handle the response from server
*/
function callback()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
if(responseDataType != "Text")
{
handlerMethod(xmlHttp.responseXML); //responseXML/Text is supposed by IE and Firefox,ResponseXML/Text only in IE
}
else
{
handlerMethod(xmlHttp.responseText);
}
}
}
};
- ajax简单创建代码
- 简单ajax代码。
- jsp+ajax 简单代码
- 创建ajax的简单方法
- 一个简单的AJAX代码
- AJAX入门及简单代码
- ajax代码及简单封装
- php+ajax简单实例代码
- Ajax 简单的实例代码
- 创建线程的简单代码
- UICollectionView 简单使用 代码创建
- 【挑战极限】最短AJAX创建代码
- 创建各种Ajax引擎的代码
- [黑马程序员]简单的ajax代码
- 简单的ajax评论完整代码
- 关于AJAX轮询简单代码
- $.get(),$.ajax(),$.getJSON()代码中简单使用
- C#创建文本文件代码(超级简单)
- JavaScript图形库
- 扩展 Visual Editor 的控件和属性
- 获取网页的信息(转)
- replaceNode 在文档树中替换对象
- linux 菜鸟磁盘分区方案推荐
- ajax简单创建代码
- Linux 的魅力:访问 Nokia N800 摄像机
- HTML 标签
- socket模型使归纳
- 使用 RESTful 界面和 Project Zero 管理 HTTP 服务器
- 用Spring快速开发jms应用(JBOSS服务器)
- 表格链接
- 什么是封闭式基金?如何买卖?
- TCP/IP_UDP归纳