标签:ajax 学习
js eval函数
eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码。
<script type="text/javascript">
eval("x=10;y=20;document.write(x*y)")
document.write(eval("2+2"))
var x=10
document.write(eval(x+17))
</script>200 4 27
ajax 利用XMLHttpRequest对象,进行异步或者同步请求。
function createXMLHtppRequest()
{
if(window.ActiveXOject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}方法获得一个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","test1.txt",true);
xmlhttp.send();当使用 async=true 时,请规定在响应处于 onreadystatechange 事件中的就绪状态时执行的函数:
xmlhttp.open("GET","test1.txt",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;不推荐使用false:
标签:ajax 学习
原文地址:http://10750710.blog.51cto.com/10740710/1951966