2015-07-09 34 views
0

我想從json中讀取對象並顯示未定義。我能否得到幫助?下面是我的代碼。而不是從數據庫中獲取名稱,它顯示未定義。我認爲問題在於我的成功功能。請幫助我。Json讀取顯示未定義的對象

<script> 
$(document).ready(function(){ 
    $.ajax({ 
     type: 'GET', 
     url: 'connections/profile.php', 
     data: 'param=no' , 
     ataType: "html", 
     success: function (response) { 
      console.log(response); 
       $('#basicContent').html('<h4><b>' + response.name + '</b></h4>'); 

     }, 
     error: function (e){ 
      alert (e); 
     } 

    }); 
}); 
</script> 

也是我的PHP從html

<?php 
require_once('connect.php'); 
session_start(); 
if (!isset ($_SESSION['matric'])) 
{ 
$go="index.html"; 
header("Location:".$go); 
} 

$matric = $_SESSION['matric']; 
$pass= $dbh->prepare("SELECT * FROM users WHERE matric=:matric"); 
$pass->bindParam(':matric', $matric); 
$pass->execute(); 
$profile=$pass->fetch(PDO::FETCH_ASSOC); 
$response = array(
'name' => $profile['name'], 
'matric' => $matric, 
'school' => $profile['school'] 
); 
echo json_encode($response); 
+0

我們能看到一個例子某些被解碼爲'undefined'的JSON? –

回答

1

更改數據類型爲JSON

而且在php文件中添加頁眉服務JSON內容

header('Content-Type: application/json');