- xredleaf
- 等级: 初级会员
- 文章: 57
- 积分: 30
- 来自: 浙江
|
写了个ajax调用的js,以备自己以后再用
js 代码
- var xmlHttp;
- function createXMLHttpRequest(){
- if (window.ActiveXObject){
- var version = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0",
- "MSXML.XMLHttp.3.0","MSXML.XMLHttp","Microsoft.XMLHttp"];
- for(var i = 0; i < version.length; i++ ){
- try{
- var oXmlHttp = new ActiveXObject(version[i]);
- return oXmlHttp;
- }catch(oError){}
- }
- }else if (window.XMLHttpRequest){
- var oXmlHttp = new XMLhttpRequest();
- return oXmlHttp;
- }
- throw new Error("不能创建XMLHttp对象,请确认您的电脑上已安装了XMLHttp对象!");
- }
- function sendRequest(url,param,callBack,sync) {
- if(!xmlHttp) xmlHttp = createXMLHttpRequest();
- xmlHttp.open("post",url,sync);
- xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4) {
- if (xmlHttp.status == 200) {
- callBack(xmlHttp.responseXML);
- }
- }
- }
- xmlHttp.send(param);
- }
- function addParam(params,paramName,paramValue) {
- var param = encodeURIComponent(paramName) + "=" + encodeURIComponent(paramValue);
- params.push(param);
- }
- function getParams(params) {
- var time = new Date().getTime();
- params.push(time);
- return params.join("&");
- }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|