虚拟服务器获取数据,老是提示有个奇怪的符号是什么原因?

https://img1.mukewang.com/5b17db600001c1dc05450032.jpg


<body>


         <div id="wrap">

                 <ul id='list'>

                

                 </ul>

         </div>


        <button id='btn'>按钮</button>


        <div><img src="1.jpg" alt="" /></div>

<script type="text/javascript">

             var oList = document.getElementById('list');

              var oBtn = document.getElementById('btn');

                setInterval(auto , 2000);//每隔两秒钟局部刷新一下页面,就是异步

function auto(){

         var xhr = new XMLHttpRequest();

         xhr.open( 'get' , 'test.php' , true )

         xhr.send();

         xhr.onreadystatechange = function(){

         if ( xhr.readyState == 4 )

         {

                 if ( xhr.status>=200&&xhr.status<300 )

                 {

                          var respone=eval('('+xhr.responseText+')');//返回后台的数据,拿到后爱怎么处理怎么处理

                          oList.innerHTML = '';//将旧的数据清空避免循环增加旧的数组

                         for (var i=0;i<respone.length;i++ )

                         {

                                 var s = '<li>姓名:' + respone[i].name + ',年龄:' + respone[i].age + '</li>';

                                 oList.innerHTML += s;//前面做了清空,没有新的不会添加

                         }

                }else

                  {

                  alert( '请求好像遇到了点问题,状态码:' + xhr.status );//状态码不是404 就不会报错

                 };

            }

    };

};


</script>

</body>

</html>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

<?php

header('content-type:text/html;charset="utf-8"');

// var arr = [{name:'阿飞',age:18} , {name:'excel',age:38}];


             $arr = array(

                             array('name'=>'KING' , 'age'=>'28'),

                             array('name'=>'小杨' , 'age'=>'58'),

                             array('name'=>'OMW' , 'age'=>'18'),

                             array('name'=>'农工' , 'age'=>'38'),

                             array('name'=>'小菜鸟' , 'age'=>'20'),

                             array('name'=>'我不姓邪' , 'age'=>'80'),

                             array('name'=>'blue' , 'age'=>'17')

                             array('name'=>'OMW' , 'age'=>'18'),

                             array('name'=>'农工' , 'age'=>'38'),

                             array('name'=>'小菜鸟' , 'age'=>'20'),

                             array('name'=>'我不姓邪' , 'age'=>'80'),

                             array('name'=>'blue' , 'age'=>'17')

             );


echo json_encode($arr);

?>



qq_唔叫咩_0
浏览 1364回答 2
2回答

慕田峪5445673

json格式错误,主要是代码是内容错误引起的。你可以检查一下代码

野生码农在线co腚

大哥,是43行出现语法错误。奇怪的符号。。。。晕了
打开App,查看更多内容
随时随地看视频慕课网APP