The problem is that the alert message "TEST" does not appear, although the function getData.php
is successfully executed and returns some data. I checked it in Firelog, where I can see the following output:
Array{"arr":[["1","EZY14ZM","2013-05-29 16:44:38","2013-05-29 16:45:28"],["1","VLG1307","2013-05-29 16:47:05","2013-05-29 16:47:55"],["1","WZZ212","2013-05-29 16:49:12","2013-05-29 16:50:02"]],"dep":[["1","VLG8306","2013-05-29 16:59:17","2013-05-29 17:00:00"],["1","VLG3786","2013-05-29 17:07:29","2013-05-29 17:08:12"],["1","IBE1851","2013-05-29 17:08:38","2013-05-29 17:09:21"],["1","DLH58Y","2013-05-29 17:09:47","2013-05-29 17:10:30"]]}
How to solve this problem?
function show_data() {
$.getJSON(
'h_index.php?module=mod_1&pag_mod=getData.php',
function(data) {
alert("TEST");
}
);
}
getData.php
<?php
//...
echo json_encode(array('arr' => $rows_arr, 'dep' => $rows_dep););
die();
?>
Quote: your data as viewed in Firebug:
Array{"arr":[["1","EZY14ZM","2013-05-29 16:44 .....
Note the Array
at the start of that..... this is not valid JSON.
The actual json_encode()
function you're calling is fine. It does have an extra stray semi-colon, but that's invalid PHP syntax, so I assume it's crept in when you posted the question rather than being in your actual code.
So the stray text Array
is not being produced by the json_encode()
function, so it must be coming from somewhere else in your PHP. Look for an echo
or a print
elsewhere in your code that is outputting it by mistake. (probably by printing an array variable rather than the actual string "Array")