亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么用Ajax獲取PHP數據的時候,responseText返回的是整個PHP代碼?。肯旅媸谴a,求大牛解答

為什么用Ajax獲取PHP數據的時候,responseText返回的是整個PHP代碼啊?下面是代碼,求大牛解答

一壺時光 2018-09-13 14:54:16
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title></title> <script type="text/javascript"></script></head><body> <ul> </ul> <script type="text/javascript"> var xhr = new XMLHttpRequest(); xhr.open("GET","users.php?id=2"); xhr.send(); xhr.onreadystatechange=function(){ if(this.readyState==4){ console.log(this.responseText); } } </script></body></html>//PHP代碼<?phpheader('Content-Type: application/json');$data = array(? array(? ? 'id' => 1,? ? 'name' => '張三',? ? 'age' => 18? ),? array(? ? 'id' => 2,? ? 'name' => '李四',? ? 'age' => 20? ),? array(? ? 'id' => 3,? ? 'name' => '二傻子',? ? 'age' => 18? ),? array(? ? 'id' => 4,? ? 'name' => '三愣子',? ? 'age' => 19? ));if (empty($_GET['id'])) {? $json = json_encode($data);?? echo $json;}?else{?? foreach ($data as $item) {? ? if ($item['id'] != $_GET['id']) continue;? ? $json = json_encode($item);?? ? echo $json;? }}
查看完整描述

4 回答

  • 4 回答
  • 0 關注
  • 2261 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號