I'm able to convert my data into JSON format in php and while sending that data to Ajax call, I'm not able to get the details. In fact first the length of Json data shows 87, where it is actually 2.
My php code is
// credentials of MySql database.
$username = "root";
$password = "admin";
$hostname = "localhost";
$data = array();
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("Angular",$dbhandle)
or die("Could not select Angular");
//execute the SQL query and return records
$result = mysql_query("SELECT id,name,password FROM User");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
$id = $row{'id'};
$name = $row{'name'};
$password = $row{'password'};
$data[] = array('id' => $id, 'name' => $name, 'password' => $password);
}
echo json_encode($data);
Output it shows is
[
{
"id": "1",
"name": "Rafael",
"password": "rafael"
},
{
"id": "2",
"name": "Nadal",
"password": "nadal"
}
]
My Ajax call is
$.ajax({
type: "GET",
url: "ListUsers.php",
success: function (dataCheck) {
console.log(dataCheck.length);
for(index in dataCheck) {
/*
console.log("Id:"+dataCheck[index].id);
console.log("Name:"+dataCheck[index].name);
console.log("Password:"+dataCheck[index].password);*/
}
},
error: function () {
alert("Error");
}
});
Please let me know if there is any thing wrong in my code