Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-Type: application/json");
- include_once("config.php");
- $result = mysqli_query($mysqli, "SELECT * FROM gastos ORDER BY RAND() LIMIT 1;");
- $linea = array();
- while($row = mysqli_fetch_array($result))
- {
- $id=$row['id'];
- $importe=$row['importe'];
- $concepto=$row['concepto'];
- $fecha=$row['fecha'];
- $linea[] = array('id'=> $id, 'importe'=> $importe, 'concepto'=> $concepto, 'fecha'=> $fecha);
- }
- $json_string = json_encode($linea);
- echo $json_string;
- $file = 'linea.json';
- file_put_contents($file, $json_string);
- ?>
- function loadDoc() {
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- var response = JSON.parse( this.responseText );
- consolé.log( response );
- }
- };
- xhttp.open("GET", "tu-script.php", true);
- xhttp.send();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement