温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:Ajax实现无刷新添加和删除数据源码
当前文件路径:AjaxInsertDelete/js/ajax_func.js

1var http_request = false; 2
function send_request(method,url,content,responseType,callback){ 3
http_request=false; 4
if(window.XMLHttpRequest){//Mozilla浏览器 5
http_request=new XMLHttpRequest(); 6
if(http_request.overrideMimeType){ 7
http_request.overrideMimeType("text/xml"); 8
} 9
} 10
else{ 11
try{ 12
http_request=new ActiveXObject("Msxml2.XMLHTTP"); 13
}catch(e){ 14
try{ 15
http_request=new ActiveXObject("Microsoft.XMLHTTP"); 16
}catch(e){} 17
} 18
} 19
if(!http_request){ 20
window.alert("不能创建XMLHttpRequest对象实例。"); 21
return false; 22
} 23
if(responseType.toLowerCase()=="text"){ 24
http_request.onreadystatechange=callback; 25
}else{ 26
27
window.alert("响应类别参数错误。"); 28
return false; 29
} 30
if(method.toLowerCase()=="get"){ 31
http_request.open(method,url,true); 32
http_request.setRequestHeader("If-Modified-Since", "0"); //清除缓存啊 33
} 34
else if(method.toLowerCase()=="post"){ 35
http_request.open(method,url,true); 36
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 37
}else{ 38
window.alert("http请求类别参数错误。"); 39
return false; 40
} 41
http_request.send(content); 42
} 43
//处理返回文本格式信息的函数 44
function processTextResponse(){ 45
if(http_request.readyState==4){ 46
if(http_request.status==200){ 47
alert("Text文档响应"); 48
}else{ 49
alert("您所请求的页面有异常。"); 50
} 51
} 52
} 53
function processXMLResponse(){ 54
if(http_request.readyState==4){ 55
if(http_request.status==200){ 56
alert("XML文档响应"); 57
}else{ 58
alert("您所请求的页面有异常。"); 59
} 60
} 61
}




http_request
}
}