ajax 学习

前端之家收集整理的这篇文章主要介绍了ajax 学习前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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对象,进行异步或者同步请求。

@H_502_18@functioncreateXMLHtppRequest() { if(window.ActiveXOject) { xmlhttp=newActiveXObject("Microsoft.XMLHTTP"); } elseif(window.XMLHttpRequest) { xmlhttp=newXMLHttpRequest(); } }

方法获得一个XMLHttpRequest对象。

@H_502_18@xmlhttp.open("GET","test1.txt",true); xmlhttp.send();

向服务器发送请求。

@H_502_18@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 事件中的就绪状态时执行的函数


@H_502_18@xmlhttp.open("GET",false); xmlhttp.send(); document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

不推荐使用false:

猜你在找的Ajax相关文章