I am trying to fetch an object from json and it is showing undefined. Can i get help please. below is my code.Instead of getting the name from the database it shows undefined. i think the problem is in my success function. please help me out.
<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>
also my php
<?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);
Change dataType from html
to JSON
Also in the php file add a header to serve JSON content
header('Content-Type: application/json');