日期:2014-05-17 浏览次数:20671 次
function xhr() { var xhr; try { if (window.ActiveXObject) { for ( var i = 8; i; i--) { try { if (i == 2) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } else { xhr = new ActiveXObject("Msxml2.XMLHTTP." + i + ".0"); // xhr.setRequestHeader("Content-Type","text/xml"); xhr.setRequestHeader("charset", "UTF-8"); } break; } catch (e) { xhr = false; } } } else if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); if (xhr.overrideMimeType) { xhr.overrideMimeType('text/xml'); } } } catch (e) { xhr = false; alert("您的浏览器不支持ajax"); } return xhr; } function Ajax(callBackFunc, method, url, async, data, eFunc) { var req = xhr(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { if (callBackFunc) { callBackFunc(req); } } else { if (req.readyState == 4 && req.readyState > 200) { if (eFunc) { eFunc(req); } } } if (req.readyState == 4) { req.onreadystatechange = {}; } }; method = method.toUpperCase(); req.open(method, url, async); if (method == "POST") { req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); } if (data) { req.send(data); } else { req.send(null); } } }