Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. header("Content-Type: application/json");
  4. include_once("config.php");
  5.  
  6.  
  7. $result = mysqli_query($mysqli, "SELECT * FROM gastos ORDER BY RAND() LIMIT 1;");
  8. $linea = array();
  9. while($row = mysqli_fetch_array($result))
  10. {
  11. $id=$row['id'];
  12. $importe=$row['importe'];
  13. $concepto=$row['concepto'];
  14. $fecha=$row['fecha'];
  15.  
  16.  
  17.  
  18. $linea[] = array('id'=> $id, 'importe'=> $importe, 'concepto'=> $concepto, 'fecha'=> $fecha);
  19.  
  20. }
  21.  
  22. $json_string = json_encode($linea);
  23. echo $json_string;
  24.  
  25. $file = 'linea.json';
  26. file_put_contents($file, $json_string);
  27. ?>
  28.  
  29. function loadDoc() {
  30. var xhttp = new XMLHttpRequest();
  31.  
  32. xhttp.onreadystatechange = function() {
  33. if (this.readyState == 4 && this.status == 200) {
  34. var response = JSON.parse( this.responseText );
  35. consolé.log( response );
  36. }
  37. };
  38.  
  39. xhttp.open("GET", "tu-script.php", true);
  40. xhttp.send();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement