I read most of the posts related to my question but none can resolve my simple issue.
I am using PHP and MySQLi to retrieve data from my server.
In my Database I have a one-dimensional table (i.e. one column only) and I want to put its data inside an array.
Until now I was using JSON to hold the data from my server.this is my code:
<?php
include 'ChromePhp.php';
$con=mysqli_connect("197.168.240.100","jsoncloud","nuahyu,hs","json");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
ChromePhp::warn('Failed to connect to MySQL');
}
$sql="SELECT `street` FROM `users` ";
$result=mysqli_query($con,$sql);
$rows = array();
while ($row = mysqli_fetch_all($result,MYSQLI_ASSOC)) {
$rows[] = $row[0];
}
echo json_encode($rows);
// Free result set
mysqli_free_result($result);
mysqli_close($con);
?>
My final goal is to echo the array back so I can use it with Ajax in another JS file
in the other JS file I have the following code:
$.ajax({
type: 'POST',
url: 'js/SQLusersstreets.php',
dataType: 'json',
success: function(jsonData) {
console.log(jsonData);
},
error: function() {
alert('Error loading SQLusersstreets.php from GoogleMapsCode.js');
}
});
This is my output when I open the browser's debugger:
I am trying to return a simple array, what am I doing wrong?