I'm trying to get to my data that came from php using:
echo json_encode($rows);
when I comment out datatype: 'json' I can see normally encoded json string, but when I use it alert shows me array of objects. When I try to get the length of that object array I get 1, but it should be over 20 items in there. I tried doing search posts on here and tried different things iterating through json and none of that works for me for some reason. And I am using
mysqli_set_charset($connect, "utf8");
before my select statement on php side. here is my ajax call:
function search() {
$.ajax(
{
url: "getFiles.php",
dataType: 'json',
type: "POST",
data: {Filter: $("#txtSearch").val()},
cache: false,
async: false,
success: function(data)
{
var jsonData = JSON.parse(data);
alert(data);
$.each(data, function(index, val)
{
alert(val.iddocuments);
alert(val.docName);
alert(val.fileName);
alert(val.fl1);
alert(val.dateModified);
});
}
});
}
echo json_encode($rows);gives youdataType: 'json', then thedatavariable should be already parsed as an JavaScript array, so you don't need to parse it again withJSON.parse.dataType: 'json', then put aconsole.log(data);statement insuccessfunction and tell me what it is shown in console tab, in Firebug