I have a strange problem..
When i try to access my json code with the corresponding number [0], [1] etc.. I just get the first character of the object.
First of my code:
test2.php
if(isset($_POST['getCustomersArray'])){
$runQuery = mysql_query($Query) or
die("SQL: $Query)<br />".mysql_error());
$numrows = mysql_num_rows($runQuery);
$array = array(array());
for($i = 0;$i <= 2; $i++){
$row = mysql_fetch_array($runQuery);
$array[$i]['namn'] = $row['fornamn'];
}
print json_encode($array);
}
scriptfile.js
$.ajax({
type:"POST",
url: "test2.php",
data: "getCustomersArray=true",
datatype: "JSON",
cache: false,
success: function(json) {
console.log(json[0]);
}
});
The result (from console.log(json[0])):
[
The result from just console.log(json):
[{"namn":"the first name"},{"namn":"The secound name"},{"namn":"the third name"}]
Im not sure why the squarebrackets are there but maybe they should be?
Ive been fuzzing with this problem for a while now and im sure its something stupid. Please help.