BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Description:How to use AJAX without using external libs
PHP
Kprkpr
//index.php

<div id="table"></div>

<script>
	setInterval(refreshTable,30000);
		function refreshTable{
			conexion = new XMLHttpRequest();
			// Preparar la funcion de respuesta
			conexion.onreadystatechange = function() {  /* Mostrar */
			if(conexion.readyState == 4 && conexion.status == 200) {
							document.getElementById('table').innerHTML = conexion.responseText;
					}
			}
			// Realizar peticion HTTP
			conexion.open('POST', 'https://example.org/ajax.php');
			conexion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			conexion.send("see=statustable");
		}
</script>

//ajax.php
<?php
if ($_POST['statustable']){
    return "<table><tr><td>Hello</td></tr></table>";
}

Input example

refreshtable() //AJAX call

Output example

<table><tr><td>Hello</td></tr></table>
View version's history
×Oh snap! Something wrong