AJAX
异步的 Javascript 和 XML
异步:执行这一步的同时 可以执行下一步
EX.
setTimeout setInterval
XML:它是用来传输数据的格式。
如何使用:
(function(){
//创建AJAX对象的方法
var xhr=new XMLHttpRequest() //主流浏览器
var xhr=new ActiveXObject('Microsoft.XMLHTTP')//在低版本IE浏览器中
//解决兼容性
var xhr;
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest()
}else{
xhr=new ActiveXObject('Microsoft.XMLHTTP')
}
//配置AJAX参数
xhr.open('GET',' 地址 ',true);
//true 异步 false同步
//发送请求
xhr.send('name=Luozhijian&age=20')
//请求内容
//接收服务器的响应
xhr.onreadystatechange=function(){
console.log('3')
//最后一次出发这个事件的时候,才能接受响应
if(xhr.readyState===4 && xhr.status===200){
console.log(xhr.responseText)
}
})();
eval函数
把一段字符串 当作JS代码来执行 *安全性很低 容易被黑客截取
eval('console.log("123")') //123
JSON.parse()
JSON.parse('')
//把里面的参数当作JSON文本解析
JSON.stringify
把真正的数组或对象转化成json格式的文本
YLocalStorage 本地储存
(function(){
localStorage.a='hello'
console.log(localStorage.a) //hello
//即使 浏览器关闭 或 电脑关机后 'hello' 也会保存在本地硬盘中
})()
//localStorage 中只能存入字符串