php教程 ajax返回 网页特效on数据实例<br>var xmlhttp;<br>function createxmlhttprequest()<br>{<br>//var xmlhttp=null;<br>try<br> {<br> // firefox, opera 8.0+, safari<br> xmlhttp=new xmlhttprequest();<br> }<br>catch (e)<br> {<br> // internet explorer<br> try<br> {<br> xmlhttp=new activexobject("msxml2.xmlhttp");<br> }<br> catch (e)<br> {<br> xmlhttp=new activexobject("microsoft.xmlhttp");<br> }<br> }<br>return xmlhttp;<br>}<br>function startrequest(id)<br>{<br> createxmlhttprequest();<br> try<br> { <br> url="json.php?cid="+id;<br> xmlhttp.onreadystatechange = handlestatechange;<br> xmlhttp.open("post", url, true);<br> xmlhttp.send(null);<br> }<br> catch(exception)<br> {<br> alert("xmlhttp fail");<br> }<br>}<br>function handlestatechange()<br>{<br> if(xmlhttp.readystate == 4)<br> {<br> if (xmlhttp.status == 200 || xmlhttp.status == 0)<br> {<br> var result = xmlhttp.responsetext;<br> var json = eval("(" + result + ")");<br> alert('name:'+json.name);<br> alert('age:'+json.age);<br> alert('id:'+json.id);<br> }<br> }<br>}<br>