Ajax学习

       XMLHttpRequest对象

1
2
3
4
5
6
7
8
9
10
11
function getXHR() {
//根据对象判断浏览器
if(window.XMLHttpRequest) {
//不是IE
return new XMLHttpRequest();
}else{
//IE
return new ActiveXObject("Microsoft.XMLHttp");
}
}
var xhr = getXHR();

BOM location

使用location 对象可以通过很多方式来改变浏览器的位置。如:

1
location.assign("http://www.wrox.com");

或:

1
2
window.location = "http://www.wrox.com";
location.href = "http://www.wrox.com";

另外,修改location 对象的其他属性也可以改变当前加载的页面。下面的例子展示了通过将hash、search、hostname、pathname 和port 属性设置为新值来改变URL。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//假设初始URL 为http://www.wrox.com/WileyCDA/
 
//将URL 修改为"http://www.wrox.com/WileyCDA/#section1"
location.hash = "#section1";
 
//将URL 修改为"http://www.wrox.com/WileyCDA/?q=javascript"
location.search = "?q=javascript";
 
//将URL 修改为"http://www.yahoo.com/WileyCDA/"
location.hostname = "www.yahoo.com";
 
//将URL 修改为"http://www.yahoo.com/mydir/"
location.pathname = "mydir";
 
//将URL 修改为"http://www.yahoo.com:8080/WileyCDA/"
location.port = 8080;

使用location.replace(url)会导致浏览器位置改变,但不会在历史记录中生成新记录。”后退”按钮将不可点击。

reload():

1
2
location.reload(); //重新加载(有可能从缓存中加载)
location.reload(true); //重新加载(从服务器重新加载)
 
 
 
 
原文地址:https://www.cnblogs.com/xiaohu1218/p/9664832.html