I am trying to load the PHP data on the page when it finishes loading, but it does not show me the data, here is a simple example:
<?php
$datos = new stdClass();
$datos->mensaje = "hola";
header('Content-type: application/json; charset=utf-8');
$json= json_encode($datos);
echo $json;
?>
that is tomardatos.php, here the ajax code
window.onload = function () {
$.getJSON("Tomardatos.php", exito);
};
function exito(data) {
alert(data.mensaje);
}
I saw that .getJSON is to get data from the server, but it does not work, I hope your help, thanks:)