js eval函数
eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码。
<scripttype="text/javascript">
eval("x=10;y=20;document.write(x*y)")
document.write(eval("2+2"))
varx=10
document.write(eval(x+17))
</script>
200 4 27
ajax 利用XMLHttpRequest对象,进行异步或者同步请求。
functioncreateXMLHtppRequest()
{
if(window.ActiveXOject)
{
xmlhttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(window.XMLHttpRequest)
{
xmlhttp=newXMLHttpRequest();
}
}
方法获得一个XMLHttpRequest对象。
xmlhttp.open("GET","test1.txt",true);
xmlhttp.send();
向服务器发送请求。
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",true);
xmlhttp.send();
当使用 async=true 时,请规定在响应处于 onreadystatechange 事件中的就绪状态时执行的函数:
xmlhttp.open("GET",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
不推荐使用false: