使用源生JS封装提高响应效率
/**
* 跳转框架
* @param url 跳转路径
* @param pageName 页面名称(方便做面包屑导航等)
*/
function targetPage(url,pageName) {//处理浏览器兼容问题
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp=new XMLHttpRequest();
}
else {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState == 4) {//根据状态码做相应判断
if (xmlHttp.status == 200) {
console.log("成功了哦")
$('#container').html(xmlHttp.responseText);
}
else if (xmlHttp.status == 404){
alert("404");
return;
}
else if (xmlHttp.status == 403) {
alert("403");
return;
}else {
alert(xmlHttp.status + "未知错误");
return;
}
}
};
xmlHttp.open("GET", url, true);//get请求,异步
xmlHttp.overrideMimeType("text/html;charset=utf-8");//头部信息
xmlHttp.send();//发送数据
}