Hello i am getting an error TypeError: data is null i can't find the error.
js
<script>
$(document).ready(function()
{
username='<?php echo $_GET['public_username']; ?>';
apiBaseUrl='<?php echo $base_url; ?>';
singleArtist(apiBaseUrl,username);
});
function singleArtist(apiBaseUrl,username)
{
var html ='';
var encodedata=JSON.stringify({"username":username});
var url=apiBaseUrl+'api/singleArtist';
ajaxPost(url,encodedata, function(data) {
if(data.length)
{
$.each(data, function(i,data)
{
html += 'dddddd';
});
$('#singleArtist').html( html );
}
});
}
</script>
php
function singleArtist()
{
$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
$username=$data->username;
$sql = "SELECT * FROM users WHERE username=:username ";
try {
$db = getDB();
$stmt = $db->prepare($sql);
$stmt->bindParam("username", $username,PDO::PARAM_STR);
$stmt->execute();
$singleArtist = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo '{"singleArtist": ' . json_encode($singleArtist) . '}';
} catch(PDOException $e) {
echo '{"error":{"text49":'. $e->getMessage() .'}}';
}
}