Hello i want to return data using jquery like this
function countries()
{
var html='';
var j='';
var encodedata=JSON.stringify({});
var url=apiBaseUrl+'api/countries';
ajaxPost(url,encodedata, function(data) {
if(data.countries.length)
{
$.each(data.countries, function(i,data)
{
html= '<div class="panel panel-default">'+
'<div class="panel-heading">'+'<a href="'+data.country_id+'" class="feed-author" target="_blank">'+data.name+'</a>'+'</div>'+'</div>';
});
}
});
}
and this is php
function countries() {
try {
$db = getDB();
$sql = "SELECT * FROM countries";
$stmt = $db->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
return $data[0];
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
first i dont know what to put in this line
`**var encodedata=JSON.stringify({});**`
and secondly how to i return the html in this div
<div id="allcountries">