JOE个人网站

JOE个人网站,不仅仅是一个网站,更像是一个展现自我的平台,致力于让朋友们都可以
有所感触,有所收获。

json

2017-12-19 15:35:03
<script>
   function show(){
    //1.生成ajax对象
    if(window.XMLHttpRequest){
     oajax=new XMLHttpRequest();
    }else{
     oajax=new ActiveXObject('Microsoft.XMLHTTP');
    }
    //2.打开ajax连接
    oajax.open('get','http://www.ztz.com/59_gaoji/3_25/jsonp/check2.php',true);
    //3.发送
    oajax.send();
    //4.根据状态处理
    oajax.onreadystatechange=function(){
     if(oajax.readyState==4 && oajax.status==200){
      document.getElementById('box').innerHTML=oajax.responseText;
     }
    }
    /*
    //1.动态创建script对象
    var oscript=document.createElement('script');
    //2.给予该对象一个src属性,指向一个跨域的脚本
    oscript.src='http://127.0.0.1/59_gaoji/3_25/jsonp/check.php';
    //3.将script对象写入到页面中
    document.body.appendChild(oscript);
    */
   }

   function ztz(d){
     document.getElementById('box').innerHTML=d[0];
   }
  </script>
 </head>
 <body>
  <div id='box' style='width:500px; height:50px;background:yellow'>
  </div>
  <button onclick='show()'>按我</button>
  <script>
   document.write(new Date());
  </script>
 </body>
-----------------check.php-----------------
<?php
 $arr=array('a','b');
 $str=json_encode($arr);
 echo "ztz({$str})";
?>
-------------------check2.php-----------
<?php
 echo "abc";
?>