json数据返回
<script type="text/javascript"> function xmlpage(){ var xhr=new XMLHttpRequest(); xhr.onreadystatechange=function(){ if(xhr.readyState===4){ eval("var obj="+xhr.responseText); var str="地址"+obj.weatherinfo.city+"温度"+obj.weatherinfo.temp+"风向"+obj.weatherinfo.WD; document.getElementById("tq").innerHTML=str; } } xhr.open("GET","/6.php"); xhr.send(null); } window.onload=function(){ xmlpage();}; </script> <div id="tq"></div>
<?php echo '{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"10","WD":"东南风","WS":"2级","SD":"26%","WSE":"2","time":"10:25","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暂无实况","qy":"1012"}}'; ?>