I am working on ajax and php,I want to use Php array in javascript,But right not unable to integrate Php array to javascript,
Here is my Controller code where i am getting Php array as json(Using Json encode)
function GetFollowingCoinUsers()
{
$CoinId=$_POST['coin_id'];
$result = $this->M_main->GetAllCoinFollower($CoinId);
$UserId=array();
foreach($result as $res)
{
$UserId[]=$res['UserId'];
}
echo json_encode($UserId);
}
Above code give me result in following way
["463","500","505"]
And i am trying to use this array in Javascript/Ajax Response
$.ajax({
type: "post",
url:'<?php echo base_url();?>Main/GetFollowingCoinUsers',
data: {coin_id:coin_id},
success: function (datan) {
var cars = datan;
let text = "";
for (let i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
alert(text);
}
});